1. 程式人生 > 實用技巧 >2020.8.20第四十五天

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.明天繼續寫例題