Given a one-hundred-point system score, it is required to output five grades of grades'A','B','C','D', and'E'.
(if~else)
import java.util.Scanner;
public class test2 {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.println("进入成绩查询系统");
System.out.println("输入成绩:\n");
int i=input.nextInt();
if(i>=90){
System.out.println("成绩等级为A");
}
else if((i>=80)&&(i<90)) {
System.out.println("成绩等级为B");
}
else if((i>=70)&&(i<80)) {
System.out.println("成绩等级为C");
}
else if((i>=60)&&(i<70)) {
System.out.println("成绩等级为E");
}
else{
System.out.println("成绩等级为F");
}
}
}
The writing function requires the output of the percentile system score segment according to the grade of the test score. A grade is 85 points or more, B grade is 70 to 84 points, C grade is 60 to 69 points, and D grade is 60 points or less. The grade of achievement is input by keyboard.
(switch)
import java.util.Scanner;
public class Csj02 {
public static void main(String[] args) {
Scanner ra = new Scanner(System.in);
System.out.println("请输入成绩的等级:");
char rank = ra.next().charAt(0);
switch (rank) {
case 'a':
case 'A':
System.out.println("成绩为85分以上"); // String a="a";字符串 char b='b';字符 String c="a"+'b';自动向上转型
break; case 'b':
case 'B':
System.out.println("成绩为70~84分");
break;
case 'c':
case 'C':
System.out.println("成绩为60~69分");
break;
case 'd':
case 'D':
System.out.println("成绩为60分以下");
break;
default:
System.out.println("输入的成绩等级错误");
}
}
}
Write a program to output the first 20 numbers in the Fibonacci sequence
(For loop structure)
public class Work8 {
public static void main(String[] args) {
// TODO Auto-generated method stub
//裴波那契数列
System.out.println("裴波那契数列的前20位数是:");
System.out.print("1\t1\t");
int first = 1;
int second = 1;
int next=0;
for (int i = 3; i < 21; i++) {
next = first+second;
first = second;
second = next;
System.out.print(next+"\t");
if(i%5==0){
System.out.println("");//默认加一个换行符
}
}
}
}