Two Java Programs solved with using if else condi onal statement
1.) Write a Java program to convert seconds to hours, minutes and seconds.
Sample Data :
Input Second – 86399
Output – 23:59:59
Solution Code :
import [Link].*;
public class Main {
public static void main(String[] args)
{
Scanner in = new Scanner([Link]);
[Link]("Input seconds: ");
int seconds = [Link]();
int S = seconds % 60;
int H = seconds / 60;
int M = H % 60;
H = H / 60;
[Link]( H + ":" + M + ":" + S);
[Link]("\n");
}
}
2.) write a java program to check whether a given number is positive or
negative and also find whether even or odd.
Solution Code :
public class Main {
public static void main(String[] args)
{
int num = 10;
// Checking for positive, negative or zero
if (num > 0) {
[Link]("Positive number");
}
else if (num == 0) {
[Link]("Zero");
}
else {
[Link]("Negative number");
}
// Checking for odd and even
if (num % 2 == 0) {
[Link](num + " is Even");
}
else {
[Link](num + " is Odd");
}
}
}
*Please make a new fair practical copy and start writing all the program
given in that same practical copy