day03-if-三种格式的学习与练习
This commit is contained in:
@@ -51,12 +51,42 @@ else{
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
public class Demo01_if {
|
public class Demo01_if {
|
||||||
|
//if的格式三的练习
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
int score =77;
|
||||||
|
if(score<0 || score>100){
|
||||||
|
System.out.println("你的成绩是错误的");
|
||||||
|
}else if(score>=90 && score<=100){
|
||||||
|
System.out.println("你的成绩属于优秀");
|
||||||
|
}else if(score>=80 && score<90){
|
||||||
|
System.out.println("你的成绩属于好");
|
||||||
|
}else if(score>=70 && score<80){
|
||||||
|
System.out.println("你的成绩属于良");
|
||||||
|
}else if(score>=60 && score<70){
|
||||||
|
System.out.println("你的成绩属于及格");
|
||||||
|
}else {
|
||||||
|
System.out.println("你的成绩属于不及格");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if的格式三
|
||||||
|
public static void ifMethod3(String[] args) {
|
||||||
// x和y的关系满足如下:
|
// x和y的关系满足如下:
|
||||||
// x>=3 y = 2x + 1;
|
// x>=3 y = 2x + 1;
|
||||||
//-1<=x<3 y = 2x;
|
//-1<=x<3 y = 2x;
|
||||||
// x<=-1 y = 2x – 1;
|
// x<-1 y = 2x – 1;
|
||||||
// 根据给定的x的值,计算出y的值并输出。
|
// 根据给定的x的值,计算出y的值并输出。
|
||||||
|
int x = -2;
|
||||||
|
int y;
|
||||||
|
if (x >= 3) {
|
||||||
|
y = 2*x + 1;
|
||||||
|
} else if (x>=-1 && x<3) {
|
||||||
|
y = 2*x;
|
||||||
|
} else {
|
||||||
|
y = 2*x-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(y);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user