0

I cannot figure out how to use the debugger, there is an issue with my for loop it will not do a few things. It keeps printing the 2 printf at the same time and then it will not let me add the values to the arrays. It will skip the first input line and then only let me enter in an int. I'm not sure where my mistake is and have been looking for some time.

import java.util.Scanner;

public class BarChart {

    private int NumberOfValues;  
    private String [] valueName; 
    private int [] value; 
    private int currentMax; 
    public int counter; 
    public int i; 
    Scanner input = new Scanner(System.in);

    public BarChart(String string) {

    }
    public void setValues()
        {
            System.out.println("How many sets of numbers would you like to enter?"); 
            NumberOfValues = input.nextInt();
            value = new int  [NumberOfValues];
            valueName = new String [NumberOfValues]; 

            for (int i =0; i <value.length; i++);
            {
                System.out.printf("Please enter the name of the set", + i);
                valueName [i] = input.nextLine(); 
                System.out.printf("Please enter the value ", + i);
                value[i] = input.nextInt(); 
            }

        }
  • Sometimes certain lines of code can optimized away, such that even though you see those lines in your IDE, they aren't really there when you go to debug. – Tim Biegeleisen Dec 20 '16 at 03:51
  • Where is the main method that runs this code? – OneCricketeer Dec 20 '16 at 03:58
  • input.nextLine() is for a booleen value, I changed that so my only issue now is that I cannot get my loop to loop! – John Smith Dec 20 '16 at 04:01
  • The main is in the tester class, it is calling the setValues() method – John Smith Dec 20 '16 at 04:02
  • 1
    @JohnSmith your loop seems not looping because of the use of `nextInt()` and `nextLine()`. please check it, or maybe you can try not to use `nextInt()` – Baby Dec 20 '16 at 04:13
  • @Baby,I'm not sure of another way to take the user input and assign it to an array. – John Smith Dec 20 '16 at 04:17
  • 1
    Try this please. `NumberOfValues = Integer.parseInt(input.nextLine());` – OneCricketeer Dec 20 '16 at 04:17
  • Or actually read the marked duplicate. You must clear the newline manually after a `nextInt()`, or other `next()` methods that are not `nextLine` – OneCricketeer Dec 20 '16 at 04:18
  • I did read it, all of it. Im not sure that I understand all of it though. Im not sure what im suppose to do with this "NumberOfValues = Integer.parseInt(input.nextLine());". My issue is the for loop is not looping. – John Smith Dec 20 '16 at 04:30
  • Thank you everyone for your help, the semicolon at the end of my for loop was messing everything up causing me to try all kinds of stuff. Thanks a bunch – John Smith Dec 20 '16 at 04:44

0 Answers0