-3

I cannot enter a string in run time filmType. Once it reaches the line that asks for a filmType the program ends.

public class Main {

public static void main(String[] args) {

    Scanner In = new Scanner(System.in);
    System.out.println("enter film name");

    String s = In.nextLine();
    System.out.println("enter Budget");
    int Budget=In.nextInt();

    System.out.println("enter running time");
    double running = In.nextDouble();

    System.out.println("enter film Type");
    String filmType = In.nextLine();    
 }
}
Oli
  • 6,389
  • 2
  • 9
  • 31

1 Answers1

0

The problem with your code is the use of nextInt and nextDouble. These methods do not take into account the newline \n (enter) you put in the line you entered at the specific question. This newline will that go to the next time you call a nextLine and will immediate assign an empty line to that variable.

You can for instance change your code to:

Scanner In = new Scanner(System.in);
System.out.println("enter film name");
String s = In.nextLine();

System.out.println("enter Budget");
String BudgetString = In.nextLine();

int budget = Integer.parseInteger(BudgetString); // with proper numberFormatException handling

System.out.println("enter running time");
String runningString = In.nextLine();

double running = Double.parseDouble(runningString); // with proper numberFormatException handling

System.out.println("enter film Type");
String filmType = In.nextLine();  
Stephan Hogenboom
  • 1,309
  • 2
  • 13
  • 23