1.例8.1例类
import java.util.Scanner; public class Cjava { public static void main(String[]args) { Time t=new Time(); Scanner s=new Scanner(System.in); t.hour=s.nextInt(); t.minute=s.nextInt(); t.sec=s.nextInt(); System.out.println(t.hour+":"+t.minute+":"+t.sec); } } class Time{ int hour,minute,sec; }
例8.2引用多个对象成员
import java.util.Scanner; public class Cjava { public static void main(String[]args) { Time t1=new Time();Time t2=new Time(); Scanner s=new Scanner(System.in); t1.hour=s.nextInt(); t1.minute=s.nextInt(); t1.sec=s.nextInt(); System.out.println(t1.hour+":"+t1.minute+":"+t1.sec); t2.hour=s.nextInt(); t2.minute=s.nextInt(); t2.sec=s.nextInt(); System.out.println(t2.hour+":"+t2.minute+":"+t2.sec); } } class Time{ int hour,minute,sec; }
2.没问题
3.明天继续写例题