-4
내 프로그래밍 수업 시간과 올바른 분, 초 양 (NO보다 큰 59)추가 시간 프로그램 컴파일러 오류
import java.util.Scanner;
public class AddingTime {
public static void main (String[] args) {
Scanner kbReader = new Scanner(System.in);
System.out.println("Welcome to AddingTime!");
// First Addend
System.out.println("Enter the days amount for the first addend (if none print 0): ");
int firstAddendDays = kbReader.nextInt();
System.out.println("Enter the hours amount for the first addend (in none print 0): ");
int firstAddendHours = kbReader.nextInt();
System.out.println("Enter the minutes amount for the first addend (if none print 0): ");
int firstAddendMinutes = kbReader.nextInt();
System.out.println("Enter the seconds amount for the first addend (if none print 0): ");
int firstAddendSeconds = kbReader.nextInt();
// Second Addend
System.out.println("Enter the days amount for the second addend (if none print 0): ");
int secondAddendDays = kbReader.nextInt();
System.out.println("Enter the hours amount for the second addend (in none print 0): ");
int secondAddendHours = kbReader.nextInt();
System.out.println("Enter the minutes amount for the second addend (if none print 0): ");
int secondAddendMinutes = kbReader.nextInt();
System.out.println("Enter the seconds amount for the second addend (if none print 0): ");
int secondAddendSeconds = kbReader.nextInt();
int totalSeconds = firstAddendSeconds + secondAddendSeconds;
if (totalSeconds >= 60) {
// Total Seconds if totalSeconds is larger than 60
totalSeconds = totalSeconds % 60;
// Extra minutes from totalSeconds in a decimal form
double minutesFromSeconds = totalSeconds/60;
// Changing the above into a integer form of minutes
int intMinutesFromSeconds = (int)minutesFromSeconds;
}
int totalMinutes = firstAddendMinutes + secondAddendMinutes + intMinutesFromSeconds;
if (totalMinutes >= 60) {
// Total minutes if totalMinutes is larger than 60
totalMinutes = totalMinutes % 60;
// Extra hours from totalMinutes in a decimal form
double hoursFromMinutes = totalMinutes/60;
// Changing the above into an integer form of hours
int intHoursFromMinutes = (int)hoursFromMinutes;
}
int totalHours = firstAddendHours + secondAddendHours + intHoursFromMinutes;
if (totalHours >= 24) {
// Total hours if totalHours is larger than 24
totalHours = totalHours % 24;
// Extra days from totalHours in a decimal form
double daysFromHours = totalMinutes/24;
// Changing the above into an integer form of days
int intDaysFromHours = (int)daysFromHours;
}
int totalDays = firstAddendDays + secondAddendDays + intDaysFromHours;
System.out.println("Your total calculated time is " + totalDays + "days" + totalHours + "hours" + totalMinutes + "minutes" + totalSeconds + "seconds");;
}
}
로 변환을 추가하는 프로그램을 만들도록 지시했다 이 코드를 컴파일하면 변수 intMinutesFromSeconds, intHoursFromSeconds 및 intDaysFromHours에서 기호 오류를 찾을 수 없다는 메시지가 나타납니다. 그러나 나는 내가 잘못한 것을 이해하지 못한다.
그것은 지금 작동 – GamingWithHan
를 초기화되지 않았을 수 있습니다! 감사! – GamingWithHan