和小学的题目结果还有点不一样,呵呵,小学的题目是要求指针完全重合,而且不完全是整数的。
public class GetTime { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
int ch =0;
int h = 0;
int m = 0;
int s = 0;
StringBuffer sb = new StringBuffer();
for(h=0;h<12;h++){
for(m=0;m<60;m++){
for(s=0;s<60;s++){
ch = h*5+m/12;
System.out.println(m/12);
if(m==s&&ch==m)
sb.append(","+h+":"+m+":"+s);
}
}
}
System.out.println("time="+sb.toString().substring(1));
}}

解决方案 »

  1.   

    time=0:0:0,1:5:5,2:10:10,3:16:16,4:21:21,5:27:27,6:32:32,7:38:38,8:43:43,9:49:49,10:54:54,11:59:59
    闪了,另外一个回来再整。可以倒过来考虑,实际上是到遇到第4个商店之后遇到第5个人喝光了酒。
      

  2.   

    秒针60秒是360°,分针60*60=3600秒是360°,时针12*60*60=43200秒是360°,所以每秒钟秒针分针时针走的度数分别是6°,0.1°,1/120°设从0点0分0秒过了x秒(x<43200),则秒针走了[6x(mod)360]°{注:mod是取余},分针走了[x/10(mod)360]°,时针走了x/120度。因为秒针度数为6的倍数,为了时针能和秒针重合,x/120也应为6的倍数,所以x为720的倍数,即x=720n,所以三针要重合,秒针只能走0°,因为6*720n(mod)360=0。所以三针只可能在12点处重合。即一天只有两次重合机会,12点和24点。好理解吧。o(∩_∩)o... 
      

  3.   


    public class Test{

    public static void main(String[] args) {
    for(int h=0;h<120;h+=5) {
    for(int m=0;m<60;m++) {
    for(int s=0;s<60;s++) {
    if(((h>60)?h-60:h) == m && m== s) System.out.println(h/5+":"+m+":"+s);
    }
    }
    }
    }

    输出:
    0:0:0
    1:5:5
    2:10:10
    3:15:15
    4:20:20
    5:25:25
    6:30:30
    7:35:35
    8:40:40
    9:45:45
    10:50:50
    11:55:55
    13:5:5
    14:10:10
    15:15:15
    16:20:20
    17:25:25
    18:30:30
    19:35:35
    20:40:40
    21:45:45
    22:50:50
    23:55:55
      

  4.   

    更改,之前的程序有个小问题12:0:0没输出来:
    public class Test{

    public static void main(String[] args) {
    for(int h=0;h<120;h+=5) {
    for(int m=0;m<60;m++) {
    for(int s=0;s<60;s++) {
    if(((h>=60)?h-60:h) == m && m== s) System.out.println(h/5+":"+m+":"+s);
    }
    }
    }
    }

    输出:
    0:0:0
    1:5:5
    2:10:10
    3:15:15
    4:20:20
    5:25:25
    6:30:30
    7:35:35
    8:40:40
    9:45:45
    10:50:50
    11:55:55
    12:0:0
    13:5:5
    14:10:10
    15:15:15
    16:20:20
    17:25:25
    18:30:30
    19:35:35
    20:40:40
    21:45:45
    22:50:50
    23:55:55
      

  5.   

    package time;public class TimeDemo {
      
    public static void main(String args[]){
    for(int i=0;i<=86400;i++){
    if((6*i)%360==(0.1*i)%360){
    if((0.1*i)%360==(1/120.0)*i%360){
      System.out.println(i/3600+":"+i%3600/60+":"+i%3600%60/60);
    }

    }

    }

    }}