Respuesta :
Answer:
Explanation:
import java.util.*;
public class Exercise55 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Do you want to run again? ")
string run = in.nextString()
System.out.print("Input seconds: ");
int seconds = in.nextInt();
Do
{
int p1 = seconds % 60;
int p2 = seconds / 60;
int p3 = p2 % 60;
p2 = p2 / 60;
System.out.print( p2 hours + ":" + p3 minutes+ ":" + p1 seconds);
System.out.print("\n");
}
while( run == yes)
}
}
Answer:
package brainly;
// import the Scanner class
import java.util.Scanner;
public class TimeConverter {
public static void main(String[] args) {
//Create an object of the Scanner class to allow for users inputs
Scanner input = new Scanner(System.in);
//Create an infinite do while loop.
//At each of the cycles in the loop,
do {
//1. Create a prompt for the user to make a selection
System.out.println("1. Seconds to hours, minutes and seconds ");
System.out.println("2. Quit ");
System.out.println("Enter 1 or 2");
// Receive the users input and store in a variable
int userselection = input.nextInt();
// if the user enters 1, ask them to enter the length of time
if (userselection == 1) {
System.out.println("Enter the length of the time in seconds ");
//Receive the length of time and store in a variable
int lengthOfTime = input.nextInt();
//Check if the length is positive
//if yes, call the converter method
if (lengthOfTime >= 0) {
converter(lengthOfTime);
}
//if no, return an error message
else {
System.out.println("");
System.err.println("Invalid input! Number should be positive");
}
}
// else if the user enters 2, break out of the loop to quit the program
else if (userselection == 2) {
System.out.println("You have quit the program");
break;
}
// else display an invalid input error message
else {
System.err.println("Invalid input! Enter 1 or 2");
}
} while (true);
} // end of main method
//The converter method
public static void converter(int lengthOfTime) {
//Convert the length of time to hours
int noOfHours = lengthOfTime / 3600;
//Convert the length of time to minutes
int noOfMinutes = (lengthOfTime % 3600) / 60;
//Convert the length of time to seconds
int noOfSeconds = lengthOfTime - (noOfMinutes * 60 + noOfHours * 3600);
//Print out the results
System.out.println(noOfHours + " hours " + noOfMinutes + " minutes " + noOfSeconds + " seconds ");
} //end of converter method
} // end of class declaration
Explanation:
The code above has been written in Java. The code contains comments explaining important sections of the code. Kindly go through the comments in the code.
The source code file has also been attached to this response. Kindly download it for better formatting and readability.