-2

When I try to run the program it asks me for my input and then just says "running" without any output until I close it. I do not see any issues with the code, and I have run this exact program before on a different computer (my home computer is far superior in processing power to the PC it ran on) is this a Netbeans bug?

int ticket [] = new int [6];    
   for (int i = 0; i < 6; i++)
   {
       ticket [i] = Integer.parseInt(JOptionPane.showInputDialog("Input a number:"));
   }
   int balls[] = new int [7];
   for (int i = 0; i < balls.length; i++)
   {
       boolean keepLooking = true;
       int b = (int)(Math.random()*6 + 1);
       while(keepLooking)
       {
          keepLooking = false;
          for (int j = 0; j < balls.length; j++)
          {
              if (balls [j] == b)
              {
                  keepLooking = true;
              }
          }
       }
       balls [i] = b;
   }
   int bonus = balls[6];
   int matching = 0;
   boolean bonusMatch = false;
   for (int i = 0; i < 6; i++)
   {
      for (int j = 0; j < 7; j++)
      {
          if (ticket[i] == balls[j])
          {
              matching = matching +1;
          }
      }
      if (ticket[i] == balls[6])
      {
          bonusMatch = true;
      }
   }
   System.out.println("The winning balls are: ");
   for (int i = 0; i < 6; i++)
   {
       System.out.print(" " +balls[i]);
   }
   System.out.println(" And the bonus ball is " +balls[6]);
   int Payout = 0;
   if (matching == 3)
   {
       System.out.println("Your payout was: R57");
   }
   else if (matching == 4)
   {
       System.out.println("Your payout was: R1033");
   }
   else if (matching == 5)
   {
       if (bonusMatch = true)
       {
           System.out.println("Your payout was: R2300000");
       }
       else 
       {
           System.out.println("Your payout was: R55491");
       }
   }
   else if (matching == 6)
   {
       System.out.println("Your payout was: R14000000");
   }
}
  • I don't see a `println` with "running" anywhere in your code snippet. Are you sure this is the same code you are describing? – Tim Biegeleisen Jun 29 '16 at 16:13
  • Can you post entire code? where is your main function? how do you see "running" output if there is no output like this. – Ami Hollander Jun 29 '16 at 16:15
  • Same here, by the way you can also try to put a couple of breackpoint just to see where the program stuck... – Hooch Jun 29 '16 at 16:31
  • Possible duplicate of [What is a debugger and how can it help me diagnose problems?](http://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – Raedwald Jun 29 '16 at 17:50

2 Answers2

0

int b = (int)(Math.random()*6 + 1);

if b is twice the same (it's random, it can happen and will happen), you have an infinite loop (keepLooking = true since you found b in your table, and you iterate without changing anything). whatever you are trying to achieve (honestly your code made no sense, create methods with meaningful names, avoid intricate loops, brief refactor), bug's on you, not Netbeans.

TemporalWolf
  • 7,727
  • 1
  • 30
  • 50
  • Thank you, I will look to improve it. The code is for an IT test we wrote, I'm doing it as exam revision – Bastiaan Jun 29 '16 at 17:07
  • get used to the step by step debugger. that's how you can easily spot these kind of mistakes. And always assume you're wrong before blaming the tool, 99.99% of the time it will be the case ;) – WeirdBob Jun 29 '16 at 17:30
0

please use "if" loop instead of "while" loop you will get a output like what u want!!i.e., while(keepLooking) instead use if(keepLooking)