package com.cc.test;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int second = in.nextInt();
calc(second);
}
public static void calc(int value) {
//秒数整除3600为应有的小时数.
int hour = value / 3600;
//(秒数-已有的小时数×3600 是剩余的秒数)整除60为分钟数.
int minute = (value - hour * 3600) / 60;
//秒数-小时数×3600 - 分钟数×60为剩余的秒数.
int second = value - hour * 3600 - minute * 60;
System.out.println(hour + "h " + minute + "m " + second + "s ");
}
}
小时=time/3600
分钟=time%3600/60
秒=time%3600%60
import java.text.SimpleDateFormat;
import java.util.Scanner;
public class Test1 {
public static void main(String[] args) {
System.out.println("请输秒数:");
Scanner sc = new Scanner(System.in);
int time = sc.nextInt();
int h = time / 3600;
int m = time / 3600 % 60;
int s = time % 3600 % 60;
// SimpleDateFormat date = new SimpleDateFormat("HH:mm:ss");
// String str = date.format(null);
System.out.println(time+" 秒等于"+" "+h+"小时"+m+"分钟"+s+"秒");
}
}
public static void main(String[] args) {
System.out.println("请输秒数:");
Scanner sc = new Scanner(System.in);
int time =sc.nextInt();
int h = time/3600;
int m = time%3600/60;
int s = time%3600%60;
System.out.println("时间:"+h+":"+m+":"+s);
}
将你的三行写为int h = time/3600;
int m = time%3600/60;
int s = time%60;
这样即可!你想想就懂的!