public class Demo{
public static void main(String arg[])throws Exception{
int hour; System.out.println("请输入时间:"); hour=(int)System.in.read();
if(hour >=7 && hour < 12)
System.out.println("早上好! ");else if(hour >= 12 && hour < 15)
System.out.println("下午好 !");
else if(hour >= 15 && hour < 21)
System.out.println("晚上好 !");
else
System.out.println("晚安! ");}
}
请帮我看一下这个题 条件语句 哪里错了
可以通过编译 在运行时 无论你输入 哪个数字 结果全是输出晚安。
请大家看一下啊
public static void main(String arg[])throws Exception{
int hour; System.out.println("请输入时间:"); hour=(int)System.in.read();
if(hour >=7 && hour < 12)
System.out.println("早上好! ");else if(hour >= 12 && hour < 15)
System.out.println("下午好 !");
else if(hour >= 15 && hour < 21)
System.out.println("晚上好 !");
else
System.out.println("晚安! ");}
}
请帮我看一下这个题 条件语句 哪里错了
可以通过编译 在运行时 无论你输入 哪个数字 结果全是输出晚安。
请大家看一下啊
,修改如下
import java.io.*;
public class Demo{
public static void main(String arg[])throws Exception{
int hour = 0;
System.out.println("请输入时间:");
try {
//转换
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
hour = Integer.parseInt(br.readLine());
}catch(Exception e) {
e.printStackTrace();
}
if(hour >=7 && hour < 12)
System.out.println("早上好! "); else if(hour >= 12 && hour < 15)
System.out.println("下午好 !");
else if(hour >= 15 && hour < 21)
System.out.println("晚上好 !");
else
System.out.println("晚安! "); }
}
import java.util.Scanner;public class Demo{
public static void main(String arg[]) {
int hour = 0;
Scanner in = new Scanner(System.in); //获取标准输入流-键盘
System.out.println("请输入时间:");
if (hasNextInt()) {
hour = nextInt();
}下同
hour=Integer.parseInt(bfIn.readLine());