本次的实例是实现BJT转换为UTC(一个时间转换)
代码如下:
package test02;
import java.util.Scanner;
public class TimeT
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("请输入BJT小时");
int BJTH = in.nextInt();
System.out.println("请输入BJT分钟");
int BJTM = in.nextInt();
String h = BJTH + "";
String m = BJTM + ""; ;
String BJT = h + m;
if(BJTH<=23&&BJTM<=59)
{
if(BJTH<10)
{
if(BJTH==0)
{
if(BJTM>=10)
{
int h1 = Integer.parseInt(BJT)/100;
int m1 = Integer.parseInt(BJT)%100;
int h2 = h1 - 8;
if(h2<0){
h2 +=24;
}
int UTC=h2*100+m1;
System.out.println("UTC为"+UTC);
}else
{
int h3 = Integer.parseInt(BJT)/100;
int m2 = Integer.parseInt(BJT)%100;
int h4 = h3 - 8;
if(h4<0){
h4 +=24;
}
int UTC=h4*100+m2;
System.out.println("UTC为"+UTC);
}
}else
{
if(BJTM>=10)
{
int h5 = Integer.parseInt(BJT)/100;
int m3 = Integer.parseInt(BJT)%100;
int h6 = h5 - 8;
if(h6<0){
h6 +=24;
}
int UTC=h6*100+m3;
System.out.println("UTC为"+UTC);
}else
{
BJT = h+"0"+m;
int h7 = Integer.parseInt(BJT)/100;
int m4 = Integer.parseInt(BJT)%100;
int h8 = h7 - 8;
if(h8<0){
h8 +=24;
}
int UTC=h8*100+m4;
System.out.println("UTC为"+UTC);
}
}
}else
{
if(BJTM>=10)
{
int h9 = Integer.parseInt(BJT)/100;
int m5 = Integer.parseInt(BJT)%100;
int h10 = h9 - 8;
if(h10<0){
h10 +=24;
}
int UTC=h10*100+m5;
System.out.println("UTC为"+UTC);
}else
{
BJT = h + "0" + m;
int h11 = Integer.parseInt(BJT)/100;
int m6 = Integer.parseInt(BJT)%100;
int h12 = h11 - 8;
if(h12<0){
h12 +=24;
}
int UTC=h12*100+m6;
System.out.println("UTC为"+UTC);
}
}
}else
{
System.out.println("输入数字不合法,请重新输入!");
}
}
}
注:代码可能有些冗余,但功能没问题,后面会改进的。
欢迎有想法的小伙伴来交流探讨!