mayeye1989 2015-09-22 05:29 采纳率: 54.5%
浏览 1801
已采纳

JAVA编程作业题求教!

以下是我的JAVA课程作业,希望能够得到源代码的参考

一节课的长度为2小时30分钟,课间休息时间为10分钟,现在要求用户输入时间以后,求出下课的时间以及课间休息开始和结束的试看。

以下是用户界面的输出结果。
When does this lecture start (please indicate hours and minutes)? Hour: 14
Minute: 55
This lecture will end at
Hour: 17
Minute: 25
The mid-lecture break start time is
Hour: 16
Minute: 5
The mid-lecture break end time is
Hour: 16
Minute: 15

以下是我的源代码
package jave.util;

import java.util.Scanner;

public class Assignment1 {

public static void main(String[] args) {
Scanner M= new Scanner(System.in);
Scanner H= new Scanner(System.in);
int numberofmin=M.nextInt();
int numberofh=H.nextInt();
final int classlength=150;
final int breaklength=30;
int numberofhourover = (numberofh*60+numberofmin+classlength)/60;
int numberofminover = (numberofh*60+numberofmin+classlength)%60;
int numberofhourbreakstart = (numberofh*60+numberofmin+classlength/2)/60;
int numberofminbreakstart = (numberofh*60+numberofmin+classlength/2)%60;
int numberofhourbreakover = (numberofh*60+numberofmin+classlength/2)/60;
int numberofminbreakover = (numberofh*60+numberofmin+classlength/2)%60;
System.out.println("The lecture will end at");
System.out.println("HOUR:"+numberofhourover);
System.out.println("MIN:"+numberofminover);
// TODO Auto-generated method stub

}

}

输出的结果是错的,是什么回事呢?

  • 写回答

5条回答 默认 最新

  • a719195733 2015-09-22 06:14
    关注

    import java.util.*;
    import java.text.SimpleDateFormat;

    public class TestRest{
    public static void main(String args[])throws Exception{
    //输入格式18:00
    Scanner sc=new Scanner(System.in);
    String time=sc.nextLine()+":00";
    SimpleDateFormat format = new SimpleDateFormat("hh:mm:ss");
    Long l=format.parse(time).getTime();
    //加上70分钟
    l=l+70*60*1000L;
    Date date=new Date();
    date.setTime(l);
    System.out.println("Begin Time :"+time);
    System.out.println("Rest Time :"+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
    //剩下按照上面的+10分钟
    //再加70分钟
    }
    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波