java语言写出:输入一个秒数。转换为小时:分:秒的格式输出。 10
展开全部
Java程序:
import java.util.Scanner;
public class test {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num;
int hour = 0;
int minute = 0;
int second = 0;
System.out.print("请输入秒数:");
num = scan.nextInt();
second = num % 60;
num -= second;
if(num > 0) {
num /= 60;
minute = num % 60;
num -= minute;
if(num > 0) {
hour = num / 60;
}
}
System.out.printf("%d:%d:%d\n", hour, minute, second);
}
}
运行测试:
请输入秒数:9876
2:44:36
2016-06-21
展开全部
import java.util.Scanner;
public class Convert{
public static void main(String[] args){
System.out.println("请输入时分秒,格式为hh:mi:ss");
Scanner input=new Scanner(System.in);
String s=input.next();
int index1=s.indexOf(":");
int index2=s.indexOf(":",index1+1);
int hh=Integer.parseInt(s.substring(0,index1));
int mi=Integer.parseInt(s.substring(index1+1,index2));
int ss=Integer.parseInt(s.substring(index2+1));
System.out.println(hh*60*60+mi*60+ss);
}
}
public class Convert{
public static void main(String[] args){
System.out.println("请输入时分秒,格式为hh:mi:ss");
Scanner input=new Scanner(System.in);
String s=input.next();
int index1=s.indexOf(":");
int index2=s.indexOf(":",index1+1);
int hh=Integer.parseInt(s.substring(0,index1));
int mi=Integer.parseInt(s.substring(index1+1,index2));
int ss=Integer.parseInt(s.substring(index2+1));
System.out.println(hh*60*60+mi*60+ss);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2018-01-10
展开全部
mport java.util.Scanner; public class test { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int num; int hour = 0; int minute = 0; int second = 0; System.out.print("请输入秒数:"); num = scan.nextInt(); second = num % 60; num -= second; if(num > 0) { num /= 60; minute = num % 60; num -= minute; if(num > 0) { hour = num / 60; } } System.out.printf("%d:%d:%d\n", hour, minute, second); }}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询