import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.println("Enter the name of the film");
String str = s.nextLine();
System.out.println("Enter the film budget");
int a = s.nextInt();
System.out.println("Enter the running time");
double b = s.nextDouble();
System.out.println("Enter the film production house");
String str1 = s.nextLine();
System.out.println("Film being screened : " + str);
System.out.printf("Budget : %d crores", a);
System.out.printf("\nRunning time : %.2f hours", b);
System.out.printf("\nProduction : %s", str1);
}
}
我正在获取字符串、整数、 double 和字符串的输入。但是,我无法获取我输入的“生产”值。
最佳答案
做
System.out.println("Enter the film production house");
s.nextLine();
String str1 = s.nextLine();
这是因为 s.nextDouble() 不会消耗输入的最后一个换行符,因此 str1 被分配一个“\n”(换行)值
关于java - 我给定的代码不打印最后一个输入值。代码有什么问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47573120/