import java.util.Scanner;
class ifTest
{
public static void main(String[ ] args)
{
Scanner scan=new Scanner(System.in);
System.out.println("请输入期末成绩:");
int score=scan.nextInt();
if(score==100){
System.out.println("奖励一辆BMW");
}
else if(score>80 &&score<=99){
System.out.println("奖励一台iphone xs max");
}
else if(score>=60 &&score<=80){
System.out.println("奖励一台 ipad");
}else{
System.out.println("啥也没有");
}
}
}
if else的练习
import java.util.Scanner;
class ScannerTest
{
public static void main(String[ ] args)
{
Scanner scan=new Scanner(System.in);
int num=scan.nextInt();
System.out.println(num);
}
}
/*具体实现步骤:
1.导包:import java.util.Scanner;
2.Scanner的实例化:Scanner scan =new Scanner(System.in);
3.调用Scanner类的相关方法(next()/nextXxx),来获取指定类型的变量
*/
import java.util.Scanner;
class lianxi2{
public static void main(String[ ] args){
Scanner scan =new Scanner(System.in);
System.out.println("请输入你的名字:");
String name=scan.next();
System.out.println(name);
System.out.println("请输入你的芳龄:");
int age=scan.nextInt();
System.out.println(age);
double weight=scan.nextDouble();
System.out.println("请输入你的体重:");
System.out.println(weight);
System.out.println("你是否相中我了呢?(true/false)");
boolean isLove=scan.nextBoolean();
System.out.println(isLove);
}
}
键盘输入