关于if-else结构:可以相互嵌套,当只有一条输出语句,可以去掉大括号;建议留着大括号
ackage scanner; import java.util.Scanner; public class demo05 { //输出三个整数,并又小到大一次排序 //关于if-else结构:可以相互嵌套,当只有一条输出语句,可以去掉大括号; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("第一个整数"); int z1 = scanner.nextInt(); System.out.println("第二个整数"); int z2 = scanner.nextInt(); System.out.println("第三个整数"); int z3 = scanner.nextInt(); if (z1 >= z2) { if (z3>z1){ System.out.println(z2+" "+z1+" "+z3); }else if (z3<=z1){ System.out.println(z3+" "+z2+" "+z1); }else { System.out.println(z2+" "+z3+" "+z1); } }else if (z1<=z2){ if (z3>z1){ System.out.println(z1+" "+z3+" "+z2); }else if (z1>=z3){ System.out.println(z3+" "+z1+" "+z2); }else { System.out.println(z1+" "+z2+" "+z3); } } } }
package scanner;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import java.util.Scanner;
public class demo07 {
public static void main(String[] args) {
//身高180以上,财富一千万以上,长得帅,必须加嫁,满足其中一个也可以嫁,一个也不满足不嫁
Scanner scanner = new Scanner(System.in);
System.out.println("输入身高");
int s = scanner.nextInt();
System.out.println("输入财富 千万");
int c = scanner.nextInt();
System.out.println("是否帅");
String h = scanner.next();
if (s>=180&&c>=1&&h.equals("是")){
System.out.println("非你不嫁");
}else if (s>=180||c>=1||h.equals("是")){
System.out.println("嫁吧,比上不足比下有余");
}else{
System.out.println("不嫁");
}
}
}
原文:https://www.cnblogs.com/huzh123/p/13492290.html