1.
接收用户输入的数据,判断是奇数还是偶数
package com.ithema_01;
/*
接收用户输入的数据,判断是奇数还是偶数
*/
import java.util.Scanner;
public class StudentDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个数:");
int a= sc.nextInt();
if (a%2==0){
System.out.println("该数是偶数");
}else {
System.out.println("概数是奇数");
}
}
}
2
输入数字1~7,输出对应星期几
package com.ithema_01;
/*
输入数字1~7,输出对应星期几
*/
import java.util.Scanner;
public class StudentDemo {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("请输入一个数:");
int a= sc.nextInt();
if (a==1){
System.out.println("今天星期一");
}else if (a==2){
System.out.println("今天星期二");
}else if (a==3){
System.out.println("今天星期三");
}else if (a==4){
System.out.println("今天星期四");
}else if (a==5){
System.out.println("今天星期五");
}else if (a==6){
System.out.println("今天星期六");
}else if (a==7){
System.out.println("今天星期天");
}else {
System.out.println("输入有误!");
}
}
}
3.
BMI 指数测试 BMI = 体重 (kg) / 身高² (m) 接收用户输入的身高和体重,将判断结果输出 过轻:低于18.5 正常:18.5 ~ 22.9 偏胖:23 ~ 24.9 肥胖:25 ~ 29.9 重度肥胖:高于30 极度肥胖:高于40
package com.ithema_01;
/*
BMI 指数测试 BMI = 体重 (kg) / 身高² (m)
接收用户输入的身高和体重,将判断结果输出
过轻:低于18.5
正常:18.5 ~ 22.9
偏胖:23 ~ 24.9
肥胖:25 ~ 29.9
重度肥胖:高于30
极度肥胖:高于40
*/
import java.util.Scanner;
public class StudentDemo {
public static void main(String[] args) {
System.out.println("请输入身高(m):");
double height=new Scanner(System.in).nextDouble();
System.out.println("请输入体重(kg):");
double weight=new Scanner(System.in).nextDouble();
double bmi=weight/(height*height);
if (bmi<19.5){
System.out.println("过轻");
}else if (bmi>=18.5&&bmi<=22.9) {
System.out.println("正常");
}else if (bmi>=23&&bmi<=24.9) {
System.out.println("偏胖");
}else if (bmi>=25&&bmi<=29.9) {
System.out.println("肥胖");
}else if (bmi>30&&bmi<=39.9) {
System.out.println("重度肥胖");
}else if (bmi>40){
System.out.println("极度肥胖");
}
}
}
4、
小蓝同学想买一个价值8888元的新手机,她的旧手机在二手市场能卖1880元,
而手机专卖店推出以旧换新的优惠,把她的旧手机交给店家,新手机就能够打7.5折优惠。
为了更省钱,小蓝要不要以旧换新?
package com.ithema_01;
/*
小蓝同学想买一个价值8888元的新手机,她的旧手机在二手市场能卖1880元,
而手机专卖店推出以旧换新的优惠,把她的旧手机交给店家,新手机就能够打7.5折优惠。
为了更省钱,小蓝要不要以旧换新?
*/
public class StudentDemo {
public static void main(String[] args) {
double Discount=8888*0.75;
int Sell=8888-1888;
if (Discount>Sell){
System.out.println("不以旧换新更省钱");
}else {
System.out.println("以旧换新更省钱");
}
}
}