0
import java.util.Scanner;

public class Input {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int num1, num2, sum;
    System.out.println("Type a number");
    num1 = sc.nextInt();
    System.out.println("Type another number");
    num2 = sc.nextInt();
    sum = num1 + num2;
    System.out.println("The sum of the two numbers is: " + sum);
    String cookie;
    System.out.println("What is your favorite type of cookie?");
    cookie = sc.nextLine();
    System.out.println(cookie);
  }
}

I am able to input integers fine but when it comes to the String cookie part it just prints the question and the program quits without allowing me to input my favorite cookie. Changing cookie = sc.nextLine(); to cookie = sc.next(); works but only outputs the first word. If I remove everything before the String cookie; line it allows me to input my cookie choice. I am using jGRASP.

0 Answers0