题目描述

#include <iostream>
using namespace std;

//******************** begin ********************

class myDate   //日期类
{
public:
void   setDate(int y,int m,int d) //设置年月日成员
{
year=y;
month=m;
day=d;
}
private:
int year;   //年
int month;  //月
int day;    //日
};

void printDate(myDate d)   //输出形参对象的年月日成员
{
cout<<d.year<<"-"<<d.month<<"-"<<d.day<<endl;
}

//********************* end ********************

int  main()
{
int year,month,day;
cin>>year>>month>>day;

myDate date;
date.setDate(year,month,day);

printDate(date);

return 0;
}

2015 7 2

2015-7-2

代码如下

``````import java.util.*;
import java.text.DecimalFormat;
import java.math.*;
public class Main
{
public static void main(String args[]) throws Exception
{
//Integer.parseInt(new StringBuffer(String.valueOf(a)).reverse().toString())
DecimalFormat df = new DecimalFormat("#00");
Scanner cin = new Scanner(System.in);
int year = cin.nextInt();
int month = cin.nextInt();
int day = cin.nextInt();
//int hour = cin.nextInt();
//int minute = cin.nextInt();
//int second = cin.nextInt();
String x = "-";
//String y = ":";
System.out.println(year+x+month+x+day);
//System.out.println(df.format(hour)+y+df.format(minute)+y+df.format(second));
}
}``````