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 two characters:"); String message=input.nextLine(); char str1=message.charAt(0); char str2=message.charAt(1); String major=""; String grade=""; if((str1=='M'||str1=='C'||str1=='I')&&(str2=='1'||str2=='2'||str2=='3'||str2=='4')){ if(str1=='M'){ major="Mathmatics"; }else if(str1=='C'){ major="Computer"; }else if(str1=='I'){ major="Infomation technology"; } if(str2=='1'){ grade="Freshman"; }else if(str2=='2'){ grade="Sophomore"; }else if(str2=='3'){ grade="Junior"; }else if(str2=='4'){ grade="Senior"; } System.out.println(major+" "+grade); }else System.out.println("Invalid input"); } }
页:
[1]