1. 程式人生 > >Java語言程式設計(基礎篇)第十版 4.16 4.17

Java語言程式設計(基礎篇)第十版 4.16 4.17


public class J4_16 {
	public static void main(String [] args) {
		int ch= (int)(Math.random()*25)+65;
		char ch1 = (char)ch;
		System.out.println(ch1);
		
		
	}

}


public class J4_17 {

	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 a month: ");
		String month = input.nextLine();
		System.out.print("Enter a year: ");
		int years = input.nextInt();
		

	
		switch(month) {
		case "Jan":System.out.println(month+" "+ years +" has 31 dyas");break;
		case "Feb":{
			   if((years % 4 == 0 && years %100 != 0) || years % 400 == 0)
					System.out.println(month+" "+ years +" has 29 dyas");
			   else
				   System.out.println(month+" "+ years +" has 28 dyas");
				   
		}break;
		case "Mar":System.out.println(month+" "+ years +" has 31 dyas");break;
		case "Apr":System.out.println(month+" "+ years +" has 30 dyas");break;
		case "May":System.out.println(month+" "+ years +" has 31 dyas");break;
		case "Jun":System.out.println(month+" "+ years +" has 30 dyas");break;
		case "Jul":System.out.println(month+" "+ years +" has 31 dyas");break;
		case "Aug":System.out.println(month+" "+ years +" has 31 dyas");break;
		case "Sep":System.out.println(month+" "+ years +" has 30 dyas");break;
		case "Oct":System.out.println(month+" "+ years +" has 31 dyas");break;
		case "Nov":System.out.println(month+" "+ years +" has 30 dyas");break;
		case "Dec":System.out.println(month+" "+ years +" has 31 dyas");break;
	}
	}

}