dimanche 16 février 2020

comparing the value of each round of a for loop?

Is there a way to grab the resulting number from each iteration of this loop and compare it to the next?

This is a Slot Machine Sim in Java, I'm trying to find a way to see how many of the results match. so I thought I would capture the number that is resulted from each round of the For loop and compare it to the previous one.

  1. but I have no idea how to write that?
  2. is there a better way to do this?

what I have so far:

      for (int count=1; count<= 3 ; ++count)
      {

         number = slotM.nextInt(6);

         switch (number)
         {
            case 0:
               System.out.print("-cherries-");
               break;
            case 1:
               System.out.print("-Oranges-");
               break;
            case 2:
               System.out.print("-Palms-");
               break;
            case 3:
               System.out.print("-Bells-");
               break;
            case 4:
               System.out.print("-Melones-");
               break;
            default:
               System.out.print("-Bars-");
               break;
         }
         System.out.print(number);
      }




Aucun commentaire:

Enregistrer un commentaire