标签:顺序 system col under += 关系 ack sys 执行
int i = 5; i += i *= i -= 3; -> 15 i = 5 + (5 * (5 -3)) = 15 int j = 7; j -= j *= j++; j=7-(7 *7) = -42

int i = 5, j = 9; i = i^j; j = i^j; -> j = i^j^j; ->j=i; i = i^j; ->i = i^j^i; ->i = j;
int i = 5, j = 9; i = i+j; j = i-j; -> j=i+j-j; -> j = i; i = i-j; ->i = i+j-i; ->i = j;
int i = 5, j = 9; int temp = i; i = j; j = temp;
//三元表达式的嵌套 int max = i > j ? (i > k ? i : k) : (j > k ? j : k);
//练习:输出分数所对应的等级 >=90 -A >=80 -B >=70 -C >=60 -D <60 -E
char level = score >= 90 ? ‘A‘:(score >= 80 ? ‘B‘ : (score >= 70 ? ‘C‘ : (score >=60 ? ‘D‘ : ‘E‘)));
System.out.println(level);
扩展:从控制台获取数据
import java.util.Scanner; Scanner s = new Scanner(System.in); int i = s.netInt(); //获取整数 double d = s.nextDouble(); //获取小数 String str = s.next();
import java.util.Scanner;
public class IfElseExer {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int i = s.nextInt();
int j = s.nextInt();
int k = s.nextInt();
/*
if(i < j){
if(i < k){
System.out.println(i);
} else {
System.out.println(k);
}
} else {
if(j < k){
System.out.println(j);
} else {
System.out.println(k);
}
}
*/
int min = i;
if(min > j)
min = j;
if(min > k)
min = k;
System.out.println(min);
}
}
import java.util.Scanner;
public class IfElseExer2 {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
double weight = s.nextDouble();
double price = 0;
if(weight < 0){
System.out.println("不合法的重量!!!");
} else {
if(weight <= 20){
price = weight * 0.35;
} else {
if(weight <= 100){
price = 20 * 0.35 + (weight - 20) * 0.5;
} else {
price = 20 * 0.35 + 80 * 0.5 + (weight - 100) * 0.8;
}
}
}
System.out.println(price);
}
}
或者
import java.util.Scanner;
public class IfElseIfDemo {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
double weight = s.nextDouble();
double price = 0;
if(weight < 0){
System.out.println("非法的重量!!!");
} else if(weight <= 20){
price = weight * 0.35;
} else if(weight <= 100){
price = 7 + (weight - 20) * 0.5;
} else {
price = 47 + (weight - 100) * 0.8;
}
System.out.println(price);
}
}
import java.util.Scanner;
public class IfElseIfExer {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int month = s.nextInt();
if(month < 1 || month > 12){
System.out.println("Illegal month !!!");
} else if(month > 2 && month < 6){
System.out.println("Spring");
} else if(month > 5 && month < 9){
System.out.println("Summmer");
} else if(month > 8 && month < 12){
System.out.println("Autumn");
} else {
System.out.println("Winter");
}
}
}
标签:顺序 system col under += 关系 ack sys 执行
原文地址:https://www.cnblogs.com/tangdiao/p/9416028.html