package com.promote;
public class ForDemo {
public static void main(String[] args) {
// 1到100相加求和
int sum=0;
for (int i = 0; i <=100; i++) {
sum+=i;
}
System.out.println(sum);
System.out.println("---------------");
int summ=0;
int i=0;
while (i<101) {
summ=summ+i;
i++;
}
System.out.println(summ);
System.out.println("---------------");
//输入两个数的最大那个数
int a = 10;
int b = 20;
if (a>b) {
System.out.println("最大的数是:" + a);
}else{
System.out.println("最大的数是: " + b);
}
System.out.println("------------------");
//输入三个数的最大数
int c = 10;
int d = 20;
int e =30;
if (c>e) {
if (d>e) {
System.out.println("最大数是 " + c);
}else {
System.out.println("最大数是 " + e);
}
}else{
if(d>e){
System.out.println("最大数是:" + d);
}else{
System.out.println("最大数是: " + e);
}
}
System.out.println("switch语句");
String grade = "A";
switch(grade) {
case "A":
System.out.println("优秀");
break;
case "B":
System.out.println("良好");
break;
case "C":
System.out.println("及格");
break;
default:
System.out.println("不及格");
break;
}
}
}