Java語言程式設計(基礎篇)第十版 4.18
阿新 • • 發佈:2018-12-14
public class J4_18 { public static void main(String[] args) { // TODO Auto-generated method stub java.util.Scanner input = new java.util.Scanner(System.in); System.out.print("Enter two characters: "); String ch = input.nextLine(); char ch1 = ch.charAt(0); char ch2 = ch.charAt(1); if(ch1 == 'M') System.out.print("Mathematics "); else if(ch1 == 'C') System.out.print("Computer Science "); else if(ch1 == 'I') System.out.print("informantion technology "); else { System.out.println("Invalid input"); System.exit(0); } if(ch2 == '1') System.out.println(" Freshman"); else if(ch2 == '2') System.out.println(" Sophomore"); else if(ch2 == '3') System.out.println("Junior"); else System.out.println("Senior"); } }