Priya, a software developer, is working on a project to create a simple program that finds the maximum of two integers. These integers can be either positive or negative. She needs to determine which integer is larger using the ternary operator from the given inputs and display the result.
Guide Priya in completing this project.
Input format:
The input consists of two integers separated by space.
Output format:
The output prints the maximum of the two integers.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
System.out.println(num1 > num2 ? num1 : num2);
}
Pam, Jim, and Dwight are employees at a paper company, each earning a monthly salary. They want to calculate their total combined salary to manage their team expenses.
Your task is to write a program that computes the sum of their salaries and displays the total amount.
Input format:
The input consists of three double values, representing the monthly salaries of Pam, Jim, and Dwight, respectively.
Output format:
The output prints "Rs. X"
, where X is the combined salary, rounded off to two decimal places.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
double pamSalary = scanner.nextDouble();
double jimSalary = scanner.nextDouble();
double dwightSalary = scanner.nextDouble();
double totalSalary = pamSalary + jimSalary + dwightSalary;
System.out.println("Rs. " + String.format("%.2f", totalSalary));
scanner.close();
}
Ryan is working on a coding challenge where he needs to analyze two integers. He wants to determine if both numbers are positive and they are not divisible by 2. If the condition is true, he will print a specific message; otherwise, a different message should be displayed.
Help Ryan to solve this problem using operators.
Input format:
The input consists of two space-separated integers.
Output format:
If the input numbers are positive and not divisible by 2, print:
"Both integers are positive and not multiples of 2"
If the condition is not met, print:
"The condition is not met for both integers"
public static void main(String[] args) {
java.util.Scanner sc = new java.util.Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.print((a > 0 && b > 0 && a % 2 != 0 && b % 2 != 0) ? "Both integers are positive and not multiples of 2" : "The condition is not met for both integers");
}
Vishal is playing with numbers and trying to check if the second integer is exactly twice the value of the first integer. He wants to write a program that reads two integers, checks the condition, and prints the result.
Your task is to help him in the program.
Input format:
The input consists of two integers separated by space.
Output format:
The output prints the boolean value (true
or false
) indicating whether the condition is met or not.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int firstNumber = scanner.nextInt();
int secondNumber = scanner.nextInt();
boolean isTwice = (secondNumber == 2 * firstNumber);
System.out.println(isTwice);
scanner.close();
}
Sandeep is working on a program to showcase the use of unary plus and unary minus operators. The program is intended to receive an integer input from the user, apply the unary plus and unary minus operations, and then print the results.
Your task is to help Sandeep complete this program.
Input format:
The input consists of an integer N.
Output format:
"Unary Plus: "
followed by an integer value, which represents the result of the unary plus operation."Unary Minus: "
followed by an integer value, which represents the result of the unary minus operation.public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int unaryPlus = +N;
int unaryMinus = -N;
System.out.println("Unary Plus: " + unaryPlus);
System.out.println("Unary Minus: " + unaryMinus);
scanner.close();
}
Saran is exploring operator precedence and wants to create a program that calculates a result using user input for three integer values: a
, b
, and c
. The program should adhere to the following mathematical expression:
(a + b) * c / (a - b) + (c % a)
Assist Saran in completing the program while ensuring proper adherence to operator precedence rules. Ensure the program correctly adheres to operator precedence and performs division in floating-point arithmetic to get accurate results.
Input format:
The input consists of three space-separated integers a
, b
, and c
.
Output format:
The output prints a double value, representing the result of the expression, rounded to two decimal places.
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
double result = ((a + b) * c) / (double)(a - b) + (c % a);
System.out.printf("%.2f\n", result);
scanner.close();
}