Meine Programmierung Klasse wurde angewiesen, um ein Programm zu machen, die Zeit hinzufügen würde und es in die richtigen Minuten und Sekunden Menge (nicht größer als 59.)Hinzufügen von Zeitprogramm Complier Fehler
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");;
}
}
Umwandlung Wenn ich diesen Code kompiliere, sagt er mir, dass ich einen Symbolfehler in den Variablen intMinutesFromSeconds, intHoursFromSeconds und intDaysFromHours nicht finden kann. Ich verstehe jedoch nicht, was ich falsch gemacht habe.
Es gibt mir immer noch den Fehler Variable intMinutesFromSeconds worden – GamingWithHan
vielleicht nicht initialisiert Es funktioniert jetzt! Vielen Dank! – GamingWithHan