JAVA小实例(十四)

本次的实例是实现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("输入数字不合法,请重新输入!");
	}	
		
	}
	
}

注:代码可能有些冗余,但功能没问题,后面会改进的。

欢迎有想法的小伙伴来交流探讨!

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一字赌团队阿志

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值