computer input in java

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/3

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

4 Terms

1
New cards

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();
    }
}

2
New cards

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");
    }
}

3
New cards

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);
    }
}

4
New cards

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();

}

}