0

I have four user inputs within my setAll method and each user input has a println just before it. The problem that i'm having is the order after the third println.Because it changes in the console stacking two println's one on top of other. I have had this problem before but failed to solve it. I've changed println() to print() and added a newline. I've changed the order of the print() and println() methods to find the proper output in the console. The IED i'm using is NetBeans. If the rest of the code is needed I can add it.

public static void setAll(GuitarSpecifications[] guitarSpecifications, Scanner input) {

    for (int index = 0; index < guitarSpecifications.length; index++) {
        System.out.println("Enter guitar color: ");
        String gColor = input.nextLine();
        guitarSpecifications[index].setGuitarColor(gColor);

        System.out.println("Enter guitar length: ");
        double gLength = input.nextDouble();
        guitarSpecifications[index].setGuitarLength(gLength);

        System.out.println("Enter number of strings on guitar: ");
        int gStrings = input.nextInt();
        guitarSpecifications[index].setNumStrings(gStrings);

        System.out.println("Enter guitar manufacturer: ");
        String gManufacturer = input.nextLine();
        guitarSpecifications[index].setGuitarManufacturer(gManufacturer);

    }

} 

Actual output

run: Enter guitar color: green Enter guitar length: 56.6 Enter number of strings on guitar: 7 Enter guitar manufacturer: Enter guitar color:

Expected output:

Enter guitar color: Blue Enter guitar length: 45.5 Enter number of strings on guitar: 6 Enter guitar manufacturer: Gibson

Thomas
  • 23
  • 5
  • I have no idea what you're asking.... "The output is as follows" except you didn't add any line breaks to your expected output... – RobOhRob Mar 17 '20 at 19:23
  • I added an image to this question. – Thomas Mar 17 '20 at 19:29
  • dont add links...add the expected output with the expected line breaks – RobOhRob Mar 17 '20 at 19:31
  • 1
    As far as I know, Netbeans is not an [improvised explosive device](https://en.wikipedia.org/wiki/Improvised_explosive_device_(IED)). – MC Emperor Mar 17 '20 at 19:32
  • @MCEmperor LOL, good one. That really is a bad typo, huh? – Andreas Mar 17 '20 at 19:33
  • a typical problem, when you mix `nextXXX` methods with `nextLine`. solution: use `nextLine` *only* or don't use it at all. (-> `next()`) – xerx593 Mar 17 '20 at 19:37
  • 1
    This last comment solved the problem. I changed the input.nextLine() to just input.next() and my console input problem was corrected. – Thomas Mar 17 '20 at 19:53

0 Answers0