1,搬椅子
package com.bdqn.demo;
import java.util.Scanner;
public abstract class Name {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("请输入年龄:");
int age = input.nextInt();
System.out.println("请输入性别:");
String sex = input.next();
if((age>=7)||(age>=5&&sex.equals("男"))){ //使用if结构判断
System.out.println("能搬动桌子");
}else {System.out.println("不能搬动桌子");}
}
}
2,数字输出排列
package com.baqn.demo;
import java.util.*;
public class Shu {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入3个整数:");
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
if (a < b && a < c) {
if (b < c) {
System.out.print(a + "," + b + "," + c);
}
else {
System.out.print(a + "," + c + "," + b);
}
} else if (b < a && b < c) {
if (a < c) {
System.out.println(b + "," + a + "," + c);
} else {
System.out.print(b + "," + c + "," + a);
}
} else {
if (a < b) {
System.out.print(c + "," + a + "," + b);
} else {
System.out.print(c + "," + b + "," + a);
}
}
}
}
3,整除
package com.bdqn.demo;
import java.util.*;
public class Shu {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入你的整数:");
int Num = input.nextInt();
if (Num % 3 == 0 && Num % 5 == 0) {
System.out.println("该整数是3或5的倍数");
} else {
System.out.println("该整数不能被3或5中的任何一个数整除");
}
}
}
4,奖励
package com.bdqn.demo;
import java.util.Scanner;
public class Score {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入小明的考试成绩:");
int score = input.nextInt();
if(score==100) {
System.out.println("给你买车");
}else if(score>=90) {
System.out.println("给你买mp4");
}else if(score>=60) {
System.out.println("给你买本参考书");
}else {
System.out.println("什么都没有!");
}
}
}
4,,订购机票
package com.bdqn.demo;
import java.util.Scanner;
public class Plane
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
double money = 5000.0D;
System.out.println("请输入您出行的月份:");
int yue = input.nextInt();
System.out.println("请问您选择头等还是经济:头等选1,经济选2");
int choose = input.nextInt();
if ((yue > 3) && (yue < 11)) {
if (choose == 1) {
money *= 0.9D;
}
else if (choose == 2)
money *= 0.8D;
}
else {
if (choose == 1)
money *= 0.5D;
if (choose == 2) {
money *= 0.4D;
}
}
System.out.println("您的机票价格为:" + money);
}
}