⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javashy43.java

📁 《JAVA2简明教程》课后习题及部分实验内容~
💻 JAVA
字号:
/********************************************************************************************
   					第6章习题5
   日期的常用格式具有如下两种:
		2003-11-29 和November 29, 2003
   从键盘读入第一种形式的日期,编程输出第二种形式的日期。

********************************************************************************************/
import java.io.*;

class Date1 {
	public int year;
	public int month;
	public int day;
	
	Date1(){
	}
	
	Date1(int y,int m,int d){
		this.year=y;
		this.month=m;
		this.day=d;
	}
	void print(){
		System.out.println(this.year+"-"+this.month+"-"+this.day);
	}	
}


class Date2 {
	public String month;
	public int year;
	public int day;
	
	Date2(){
	}
	Date2(String month, int year, int day) {
		this.month = month;
		this.year = year;
		this.day = day;
	}
	public void ChangeToDate(Date1 date) {
		String Month[] =
			{
				"January",
				"Februry",
				"March",
				"April",
				"May",
				"June",
				"July",
				"August",
				"September",
				"October",
				"November",
				"December" };
		this.month = Month[date.month - 1];
		this.year = date.year;
		this.day = date.day;
	}
	public void print(){
		System.out.println(this.month+" "+this.day+","+this.year);
	}
}


public class Javashy43 {
	
	public static void main(String args[ ]) throws IOException{
		
		int y=0,m=0,d=0;	
		
		// 为了从键盘读入字符串进行的设置
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		String line;
	
		System.out.print("Enter Year: ");  
		line=in.readLine( );  		// 从键盘上读取一行		
		if(line!=null)
			y=Integer.parseInt(line); // 读入年
			
		System.out.print("Enter Month: ");  
		line=in.readLine( );  		// 从键盘上读取一行		
		if(line!=null)	
			m=Integer.parseInt(line); // 读入月

		System.out.print("Enter day: ");  
		line=in.readLine( );  		// 从键盘上读取一行		
		if(line!=null)	
			d=Integer.parseInt(line); // 读入日

		Date1 date1= new Date1(y,m,d);
		date1.print();
		Date2 date2 = new Date2();
		date2.ChangeToDate(date1);
		date2.print();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -