我一直在使用扫描器类此码输入获得。当过我运行这段代码保存它仅前两个值。我不能进入第三个变量值。
//Input Code
import java.util.Scanner;
public class Input
{
public static void main(String[] args)
{
try{
Scanner s = new Scanner(System.in);
int i;
float f;
String str;
System.out.println("Enter the Integer value"); //getting.
input from user
i=s.nextInt(); //store the use entered value
System.out.println("Enter the Float value");
f=s.nextFloat();
System.out.println("Enter the String value");
str=s.nextLine();
System.out.println("\nInt: "+i+"\nFloat: "+f+"\nString
"+str); //print the final result
}
catch(Exception e)
{
System.out.print(e);
}
}
}
- - - 结束 - - -
输出: 输入整数值 4 输入的float值 4.4 输入字符串值
诠释4 浮法4.10 串
请更改s.nextline()来s.next()。有关详细信息,你可以参考下面的完整代码
import java.util.Scanner;
public class Input {
public static void main(String[] args) {
try {
Scanner s = new Scanner(System.in);
int i;
float f;
String str;
System.out.println("Enter the Integer value"); // getting.
// input from user
i = s.nextInt(); // store the use entered value
System.out.println("Enter the Float value");
f = s.nextFloat();
System.out.println("Enter the String value");
str = s.next();
System.out.println("\nInt: " + i + "\nFloat: " + f + "\nString " + str); // print the final result
} catch (Exception e) {
System.out.print(e);
}
}
}