0
import java.util.Scanner;

public class NoteIt {
    public static void main(String[]args) {

        Scanner s = new Scanner(System.in);
        int Answer;
        int i=2;

        System.out.print("\nPlease Enter your Name: ");
        String Name = s.nextLine();
        System.out.println("Welcome to Note-It "+Name+", We hope you'll enjoy our application. ");

        String[][] Main = new String[2][2];

        Main[0][0]="Create new Note";
        Main[1][0]="View My Notes";

        System.out.println("\nPlease select what to do: \n");

        for(int n=0; n<2; n++){
            System.out.println((n+1)+") "+Main[n][0]);
        }
        System.out.print("\nPlease enter your response: ");
        Answer = s.nextInt();

        if(Answer == 1){
            i++;
            Main = new String[i][2];
            System.out.print("\nTitle: ");
            Main[i-1][0]=s.nextLine();
            System.out.print("\nBody: ");
            Main[i-1][1]=s.nextLine();
        }

    }
}

I don't know why it is not asking for Title?

Ivar
  • 6,138
  • 12
  • 49
  • 61

1 Answers1

0

According to @Rohit Jain, That's because the Scanner.nextInt method does not read the newline character in your input created by hitting "Enter," and so the call to Scanner.nextLine returns after reading that newline.

Description here: check this question too

Try this it may help...

  Scanner s = new Scanner(System.in);
    int Answer;
    int i=2;

    System.out.print("\nPlease Enter your Name: ");
    String Name = s.nextLine();
    System.out.println("Welcome to Note-It "+Name+", We hope you'll enjoy our application. ");

    String[][] Main = new String[2][2];

    Main[0][0]="Create new Note";
    Main[1][0]="View My Notes";

    System.out.println("\nPlease select what to do: \n");

    for(int n=0; n<2; n++){
        System.out.println((n+1)+") "+Main[n][0]);
    }
    System.out.print("\nPlease enter your response: ");
    Answer = s.nextInt();

    if(Answer == 1){
        i++;
        Main = new String[i][2];
        System.out.print("\nTitle: ");
        Main[i-1][0]=s.next();
        System.out.print("\nBody: ");
        Main[i-1][1]=s.next();
    }
maazakn
  • 384
  • 2
  • 10