1/3
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Write a program in Java that accepts the seconds as input and converts them into the corresponding number of hours, minutes and seconds. A sample output is shown below:
import java.util.Scanner;
public class KboatTimeConvert
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter time in seconds: ");
long secs = in.nextLong();
long hrs = secs / 3600;
secs %= 3600;
long mins = secs / 60;
secs %= 60;
System.out.println(hrs + " Hour(s) " + mins
+ " Minute(s) " + secs + " Second(s)");
in.close();
}
}
Write a program in java to input the temperature in Fahrenheit, convert it into Celsius and display the value in the Terminal window. A sample output is displayed below:
import java.util.Scanner;
public class KboatTemperature
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("Enter temperature in Fahrenheit: ");
double f = in.nextDouble();
double c = (f - 32) * 5.0 / 9.0;
System.out.println(f + " degree Fahrenheit = " + c + " degree Celsius");
}
}
Write a program to calculate the gross salary of an employee when
Basic Salary = Rs.8600
DA = 20% of Salary
HRA = 10% of Salary
CTA = 12% of the Salary.
Gross Salary = (Salary + DA + HRA + CTA)
public class KboatSalary
{
public static void main(String args[]) {
int sal = 8600;
double da = 20 / 100.0 * sal;
double hra = 10 / 100.0 * sal;
double cta = 12 / 100.0 * sal;
double gross = sal + da + hra + cta;
System.out.println("Gross Salary = " + gross);
}
}
Write a program to calculate and display the value of the given expression:
(a2+b2)/(a-b)
import java.util.Scanner;
public class ExpressionCalculator {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// Input
System.out.print("Enter value of a: ");
double a = in.nextDouble();
System.out.print("Enter value of b: ");
double b = in.nextDouble();
// Check for division by zero
if (a - b == 0) {
System.out.println("Error: Division by zero. (a - b) cannot be zero.");
} else {
// Calculate the expression
double result = (a a + b b) / (a - b);
// Output
System.out.println("The value of the expression (a^2 + b^2)/(a - b) is: " + result);
}
in.close();
}
}