面向对象程序设计上机练习五(类和对象)

版权声明:叁土 https://blog.csdn.net/qq_42847312/article/details/85052383

Problem Description
定义类Time,Time有3个公用的数据成员hour、min、sec分别表示小时、分、秒。
在主函数main中定义Time类对象t1,在主函数main中输入t1的各数据成员再并输出各数据成员。

Input
输入类对象的3个数据成员hour、min、sec。

Output
输出类对象的3个数据成员hour、min、sec。

Sample Input
9 10 11

Sample Output
9:10:11

AC代码:

import java.util.Scanner;

class Time {
	int hour, min, sec;

	public Time(int hour, int min, int sec) {
		super();
		this.hour = hour;
		this.min = min;
		this.sec = sec;
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner mi = new Scanner(System.in);
		Time t1 = new Time(mi.nextInt(), mi.nextInt(), mi.nextInt());
		System.out.println(t1.hour + ":" + t1.min + ":" + t1.sec);
		mi.close();
	}
}

————
余生还请多多指教!

猜你喜欢

转载自blog.csdn.net/qq_42847312/article/details/85052383
今日推荐