public class Demo {
public static void main(String[] args) {
System.out.println("请输入分数:");
Scanner sc = new Scanner(System.in);
int score = sc.nextInt();
switch (score/10){
case 10:
case 9:
System.out.println("A");
break;
case 8:
System.out.println("B");
break;
case 7:
case 6:
System.out.println("C");
break;
}
System.out.println("分数为:" + score);
}
}
循环结构语句
while循环
先判断后循环
for循环
i++ 先运算后赋值
++i 先复制后运算
public class Demo {
public static void main(String[] args) {
for (int i = 1; i <= 4; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
@Test
public void print(int [] arr){
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + ", ");
}
System.out.println();
}
@Test
public void bubbleSort(){
int arr [] = {2,55,69,78,41,58};
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - 1; j++) {
if (arr[j] > arr[j + 1]){
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
print(arr);
}
(1)如何找出最值
public class Demo{
public static void main(String[] args) {
int arr [] = {12,56,99,82,36,555};
int max = arr[0];
for (int i = 0; i < arr.length; i++) {
if (arr[i] > max){
max = arr[i];
}
}
System.out.println(max);
}
}