2020.8.20第四十五天

例8.1类的简单例子

 1 public class cjava {
 2     public static void main(String[] args) {
 3         Time t = new Time();
 4         Scanner s=new Scanner(System.in);
 5         t.hour=s.nextInt();
 6         t.minute=s.nextInt();
 7         t.sec=s.nextInt();
 8         System.out.println(t.hour+":"+t.minute+":"+t.sec);
 9 }
10 }
11 class Time{
12     int hour;
13     int minute;
14     int sec;
15 }

 

例8.2引用多个对象成员

 1 public class cjava {
 2     public static void main(String[] args) {
 3         Time t1 = new Time();
 4         Scanner s=new Scanner(System.in);
 5         t1.hour=s.nextInt();
 6         t1.minute=s.nextInt();
 7         t1.sec=s.nextInt();
 8         System.out.println(t1.hour+":"+t1.minute+":"+t1.sec);
 9         Time t2=new Time();
10         t2.hour=s.nextInt();
11         t2.minute=s.nextInt();
12         t2.sec=s.nextInt();
13         System.out.println(t2.hour+":"+t2.minute+":"+t2.sec);
14 }
15 }
16 class Time{
17     int hour;
18     int minute;
19     int sec;
20 }

 

 2.遇到的问题:无

3.明天继续写例题

 

posted @ 2020-08-20 20:19  敲敲代代码码  阅读(97)  评论(0编辑  收藏  举报