0

Okay, here is my problem. This is my code that I'm working on. On the first loop, it is fine. But when it goes to next loop the cursor on Applicant name won't come out. It skips to study level. Why this happening? Is something wrong with my code?

while (totalScholarship != 0) {
    System.out.println("Applicant Name: ");
    s.setsName(input.nextLine());

    System.out.println("Study Level: ");
    System.out.println("1-Pre Dip, 2-Dip 3-Degree");
    s.setiStudyLevel (input.nextInt());

    System.out.println("Personallity Score: ");
    s.setiPersonalityScore(input.nextInt());

    System.out.println("Parent Income: ");
    s.setdParentIncome(input.nextDouble());

    int iPersonalityScore = s.getiPersonalityScore();
    double dParentIncome = s.getdParentIncome();
    if (iPersonalityScore < 350) {
        if (dParentIncome >= 3000) {
            System.out.println("NOT ELIGIBLE!");
        } else {
            System.out.println("CONGRATULATIONS!");
            bEligible = true;
        }
    } else {
        System.out.println("CONGRATULATIONS!");
    }

    System.out.println("");
    System.out.println(s.toString());
}
Chris Mantle
  • 6,289
  • 2
  • 31
  • 47
JunieL
  • 77
  • 10
  • see http://stackoverflow.com/questions/13102045/skipping-nextline-after-use-nextint. Basically after you call `nextDouble()` there is still a newline character to be consumed – vandale Jun 07 '14 at 14:15
  • I would guess that input is an instance of scanner. Maybe post your sample input. – Brendan F Jun 07 '14 at 14:15

2 Answers2

0

Add input.nextLine() after this:

System.out.println ("Parent Income: ");
s.setdParentIncome (input.nextDouble());
CMPS
  • 7,505
  • 4
  • 26
  • 49
0

Because the "Enter" key you pressed after input.nextDouble() in the first iteration is received as an input inside input.nextLine() on the second iteration. That's why you felt that the input is skipped. Example:

int option = input.nextInt();
input.nextLine();  // Consume newline left-over
String str1 = input.nextLine();

So enter a input.nextLine() at the end of your loop and it will all work fine

Augustus Francis
  • 2,670
  • 4
  • 19
  • 31