如何用java实现转换为字母等级的数字?答案看帖子!
package nameyu;import java.util.Scanner;public class Test { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.print("Enter a letter grade(A、B、C、D、F) :"); String str=input.next(); char ch=str.charAt(0); if (ch=='A'){ System.out.println("The numeric value for grade "+ch+"is 4"); } else if(ch=='B'){ System.out.println("The numeric value for grade "+ch+"is 3"); } else if(ch=='C'){ System.out.println("The numeric value for grade "+ch+"is 2"); } else if(ch=='D'){ System.out.println("The numeric value for grade "+ch+"is 1"); } else if(ch=='F'){ System.out.println("The numeric value for grade "+ch+"is 0"); } else System.out.println(ch+" is an invalid grade"); } }
页:
[1]