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
  • 4,655
  • 12
  • 45
  • 50

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();
    }
Coder1
  • 111
  • 8
  • Mind sharing what you changed and why? It's hard to spot the differences. – Ivar Sep 10 '20 at 09:52
  • These two lines ====> Main[i-1][0]=s.next(); ========> Main[i-1][1]=s.next(); & its working fine. – Coder1 Sep 10 '20 at 09:54
  • Please [edit] your answer to make that clear. It is also helpful to explain why this is working fine. – Ivar Sep 10 '20 at 09:56
  • Honestly I don't know but I used this trick, If you or anyone know please explain – Coder1 Sep 10 '20 at 09:59