解题思路:
注意事项:
参考代码:
import java.util.Scanner; public class Main { private int h,m,s; public void Set(int seconds){ if (seconds>=0&&seconds<=86399) { h=seconds/3600; m=seconds%3600/60; s=seconds%60; } } public void Display(){ System.out.printf("%d:%d:%d",h,m,s); } public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int t=scanner.nextInt(); Main ma=new Main(); ma.Set(t); ma.Display(); } }
0.0分
3 人评分
import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); class Time{ private int h; private int m; private int s; public void Set(int a) { h = a/3600; m = a%3600/60; s = a%60; } public String Display() { return h+":"+m+":"+s; } } int a = scanner.nextInt(); Time time = new Time(); time.Set(a); System.out.println(time.Display()); } }
题目要求Time要在主函数中创建
伊风行 2024-07-14 15:37:42 |
import java.util.Scanner; import java.util.Set; public class Main{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); class Time{ private int h; private int m; private int s; public void Set(int a) { h = a/3600; m = a%3600/60; s = a%60; } public String Display() { return h+":"+m+":"+s; } } int a = scanner.nextInt(); Time time = new Time(); time.Set(a); System.out.println(time.Display()); } }