ConvertingSeconds.java
import java.util.Scanner;
public class ConvertingSeconds {
public static void main(String[] args) {
//Declaring variables
int fromseconds,hours,minutes,seconds,toSeconds;
//Scanner class Object is used to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//getting the number of seconds entered by the user
System.out.print(\"Enter Total Number of Seconds :\");
fromseconds=sc.nextInt();
//calling the method secondTime() by passing the seconds as arguments
String str=secondTime(fromseconds);
//Converting the string to String array where \',\' is the delimeter
String arr[]=str.split(\",\");
//Converting the String into integer
hours=Integer.parseInt(arr[0]);
minutes=Integer.parseInt(arr[1]);
seconds=Integer.parseInt(arr[2]);
//calling the method inSeconds by passing the hours,minutes,seconds as arguments
toSeconds=inSeconds(hours,minutes,seconds);
//Displaying the hours,minutes,seconds to seconds
System.out.println(hours+\" hours \"+minutes+\" minutes \"+seconds+\" seconds corresponds to
\"+toSeconds+\" seconds\");
}
/*This method will converts the hours,minutes,seconds to seconds
* Params:hours,minutes,seconds
* Return:totalSeconds
*/
private static int inSeconds(int hours, int minutes, int seconds) {
//Converting the hours,minutes and seconds to totalseconds
int totSeconds=hours*3600+minutes*60+seconds;
return totSeconds;
}
/*This method will converts the seconds to hours,minutes,seconds
* Params:total Seconds
* Return:String
*/
private static String secondTime(int totseconds) {
//Declaring variable
int secs=totseconds;
//calculating the number of hours
int hours=totseconds/3600;
totseconds=totseconds-(hours*3600);
//calculating the number of minutes
int minutes=totseconds/60;
totseconds=totseconds-(minutes*60);
//Calculating the number of seconds
int seconds=totseconds;
//displaying the total seconds to hours,minutes,seconds
System.out.println(secs+\" Seconds corresponds to \"+hours+\" hours \"+minutes+\" minutes
\"+seconds+\" seconds\");
return hours+\",\"+minutes+\",\"+seconds;
}
}
_____________________________________________
Output:
Enter Total Number of Seconds :10000
10000 Seconds corresponds to 2 hours 46 minutes 40 seconds
2 hours 46 minutes 40 seconds corresponds to 10000 seconds
_____________________________________________
Output1:
Enter Total Number of Seconds :15000
15000 Seconds corresponds to 4 hours 10 minutes 0 seconds
4 hours 10 minutes 0 seconds corresponds to 15000 seconds
_________________________________________Thank You
Solution
ConvertingSeconds.java
import java.util.Scanner;
public class ConvertingSeconds {
public static void main(String[] args) {
//Declaring variables
int fromseconds,hours,minutes,seconds,toSeconds;
//Scanner class Object is used to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//getting the number of seconds entered by the user
System.out.print(\"Enter Total Number of Seconds :\");
fromseconds=sc.nextInt();
//calling the method seco.
Trauma-Informed Leadership - Five Practical Principles
ConvertingSeconds.javaimport java.util.Scanner;public class Conv.pdf
1. ConvertingSeconds.java
import java.util.Scanner;
public class ConvertingSeconds {
public static void main(String[] args) {
//Declaring variables
int fromseconds,hours,minutes,seconds,toSeconds;
//Scanner class Object is used to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//getting the number of seconds entered by the user
System.out.print("Enter Total Number of Seconds :");
fromseconds=sc.nextInt();
//calling the method secondTime() by passing the seconds as arguments
String str=secondTime(fromseconds);
//Converting the string to String array where ',' is the delimeter
String arr[]=str.split(",");
//Converting the String into integer
hours=Integer.parseInt(arr[0]);
minutes=Integer.parseInt(arr[1]);
seconds=Integer.parseInt(arr[2]);
//calling the method inSeconds by passing the hours,minutes,seconds as arguments
toSeconds=inSeconds(hours,minutes,seconds);
//Displaying the hours,minutes,seconds to seconds
System.out.println(hours+" hours "+minutes+" minutes "+seconds+" seconds corresponds to
"+toSeconds+" seconds");
}
/*This method will converts the hours,minutes,seconds to seconds
* Params:hours,minutes,seconds
2. * Return:totalSeconds
*/
private static int inSeconds(int hours, int minutes, int seconds) {
//Converting the hours,minutes and seconds to totalseconds
int totSeconds=hours*3600+minutes*60+seconds;
return totSeconds;
}
/*This method will converts the seconds to hours,minutes,seconds
* Params:total Seconds
* Return:String
*/
private static String secondTime(int totseconds) {
//Declaring variable
int secs=totseconds;
//calculating the number of hours
int hours=totseconds/3600;
totseconds=totseconds-(hours*3600);
//calculating the number of minutes
int minutes=totseconds/60;
totseconds=totseconds-(minutes*60);
//Calculating the number of seconds
int seconds=totseconds;
//displaying the total seconds to hours,minutes,seconds
System.out.println(secs+" Seconds corresponds to "+hours+" hours "+minutes+" minutes
"+seconds+" seconds");
return hours+","+minutes+","+seconds;
}
}
_____________________________________________
3. Output:
Enter Total Number of Seconds :10000
10000 Seconds corresponds to 2 hours 46 minutes 40 seconds
2 hours 46 minutes 40 seconds corresponds to 10000 seconds
_____________________________________________
Output1:
Enter Total Number of Seconds :15000
15000 Seconds corresponds to 4 hours 10 minutes 0 seconds
4 hours 10 minutes 0 seconds corresponds to 15000 seconds
_________________________________________Thank You
Solution
ConvertingSeconds.java
import java.util.Scanner;
public class ConvertingSeconds {
public static void main(String[] args) {
//Declaring variables
int fromseconds,hours,minutes,seconds,toSeconds;
//Scanner class Object is used to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//getting the number of seconds entered by the user
System.out.print("Enter Total Number of Seconds :");
fromseconds=sc.nextInt();
//calling the method secondTime() by passing the seconds as arguments
String str=secondTime(fromseconds);
//Converting the string to String array where ',' is the delimeter
String arr[]=str.split(",");
//Converting the String into integer
hours=Integer.parseInt(arr[0]);
4. minutes=Integer.parseInt(arr[1]);
seconds=Integer.parseInt(arr[2]);
//calling the method inSeconds by passing the hours,minutes,seconds as arguments
toSeconds=inSeconds(hours,minutes,seconds);
//Displaying the hours,minutes,seconds to seconds
System.out.println(hours+" hours "+minutes+" minutes "+seconds+" seconds corresponds to
"+toSeconds+" seconds");
}
/*This method will converts the hours,minutes,seconds to seconds
* Params:hours,minutes,seconds
* Return:totalSeconds
*/
private static int inSeconds(int hours, int minutes, int seconds) {
//Converting the hours,minutes and seconds to totalseconds
int totSeconds=hours*3600+minutes*60+seconds;
return totSeconds;
}
/*This method will converts the seconds to hours,minutes,seconds
* Params:total Seconds
* Return:String
*/
private static String secondTime(int totseconds) {
//Declaring variable
int secs=totseconds;
//calculating the number of hours
int hours=totseconds/3600;
totseconds=totseconds-(hours*3600);
//calculating the number of minutes
int minutes=totseconds/60;
totseconds=totseconds-(minutes*60);
5. //Calculating the number of seconds
int seconds=totseconds;
//displaying the total seconds to hours,minutes,seconds
System.out.println(secs+" Seconds corresponds to "+hours+" hours "+minutes+" minutes
"+seconds+" seconds");
return hours+","+minutes+","+seconds;
}
}
_____________________________________________
Output:
Enter Total Number of Seconds :10000
10000 Seconds corresponds to 2 hours 46 minutes 40 seconds
2 hours 46 minutes 40 seconds corresponds to 10000 seconds
_____________________________________________
Output1:
Enter Total Number of Seconds :15000
15000 Seconds corresponds to 4 hours 10 minutes 0 seconds
4 hours 10 minutes 0 seconds corresponds to 15000 seconds
_________________________________________Thank You