Java calculates the number of times the hour, minute, and second hands coincide within 12 hours

Insert picture description here

package demo;

public class Test3 {
    
    

	public static void main(String[] args) {
    
    

		for (int s = 0; s < 60;) {
    
    
			for (int f = 0; f < 60;) {
    
    

				for (int m = 0; m < 60; m++) {
    
    
					if (s == m && f == m) {
    
    
						System.out.println("现在是:" + (s / 5) + "点" + f + "分" + m + "秒");
					}
				}
				f++;
				if (f % 12 == 0) {
    
    
					s++;
				}
			}
		}
	}
}

The print result is as follows:
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_43462140/article/details/115313762