例9.1构造函数
1 import java.util.Scanner; 2 import java.lang.*; 3 public class cjava { 4 public static void main(String[] args) { 5 Time t1= new Time(); 6 t1.set_time(); 7 t1.show_time(); 8 Time t2=new Time(); 9 t2.show_time(); 10 } 11 } 12 class Time{ 13 int hour; 14 int minute; 15 int sec; 16 Time(){ 17 hour=0; 18 minute=0; 19 sec=0; 20 } 21 void set_time() { 22 Scanner s=new Scanner(System.in); 23 hour=s.nextInt(); 24 minute=s.nextInt(); 25 sec=s.nextInt(); 26 } 27 void show_time() { 28 System.out.println(hour+":"+minute+":"+sec); 29 } 30 }
2.遇到的问题:无
3.明天继续写例题