gpt4 book ai didi

java - 类项目自动评分器说 "standard output is not what was expected"

转载 作者:行者123 更新时间:2023-11-30 09:03:27 25 4
gpt4 key购买 nike

我是 java 的新手,正在为我的类(class)做一个项目,但我总是遇到错误。

Project

Write an application that reads values representing a time duration in hours, minutes, and seconds and then prints the equivalent total number of seconds. (For example, 1 hour, 28 minutes, and 42 seconds is equivalent to 5322 seconds.)

SPECIFICATION OF PROMPTS, LABELS AND OUTPUT: Your code should use these prompts: "hours: ", "minutes: ", "seconds: ". The prompts should not force the user to type the required input on the next line. After all the inputs, the output should consist of a single line consisting of an integer (the total number of seconds) followed by a space followed by a label for the units: seconds. For example:

hours: 2
minutes: 10
seconds: 7
7807 seconds

SPECIFICATION OF NAMES: Your application class should be called Seconds

这些是 MyProgrammingLab 不断给我的错误:

pic

pic2

我的代码:

import java.util.Scanner;

public class Seconds {

public static void main (String[] args){

Scanner stdin = new Scanner(System.in);
int hours;
System.out.print("hours: ");
hours = stdin.nextInt();
int minutes;
System.out.print("minutes: ");
minutes = stdin.nextInt();
int seconds;
System.out.print("seconds: ");
seconds = stdin.nextInt();
int hourSeconds = (hours * 60) * 60;
int minuteSeconds = (minutes * 60);
int secondsTotal = hourSeconds + minuteSeconds + seconds;
System.out.println(secondsTotal + " seconds");

}
}

最佳答案

作为提示,尝试:

...
System.out.print("hours: ");
int hours = stdin.nextInt();
...

检查printprintln的区别

另请注意,您只需要打印提示,因此您只需打印:“小时:”。

分秒必争。

关于java - 类项目自动评分器说 "standard output is not what was expected",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25613879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com