2a.hands-On_Introduction to Java Muhindhar
2a.hands-On_Introduction to Java Muhindhar
Hands-on No. : 2a
Date : 13.02.2025
Question
Question Detail Level
No.
1 the value 150.50 to ‘bookPrice’. Print the price. Now, re-assign a Easy
value to ‘bookPrice’ then print ‘bookPrice’.
SOLUTION
import java.util.Scanner;
bookPrice = 200.75;
System.out.println("Updated Book Price: " + bookPrice);
}
}
Create the variables for a player's name, age, height in cm,
weight in kg, rank, and mobile number, and assign the values of
2 Easy
your choice. Display the player detail. (byte, short, int, double,
String
datatypes can be used).
SOLUTION
public class PlayerDetails {
public static void main(String[] args) {
String playerName = "John Doe";
byte age = 25;
double heightCm = 180.5;
double weightKg = 75.3;
short rank = 5;
long mobileNumber = 9876543210;
System.out.println("Player Details:");
System.out.println("Name: " + playerName);
System.out.println("Age: " + age);
System.out.println("Height: " + heightCm + " cm");
System.out.println("Weight: " + weightKg + " kg");
It is going to be hard but, hard does not mean
impossible.
1
HANDS-ON
SDE Readiness Training
System.out.println("Rank: " + rank);
System.out.println("Mobile Number: " + mobileNumber);
}
}
Read a person's name first, read another person and another.
Greet the first person first, the third person second and the
3 Easy
second person last. If ‘Chloe’, ‘Joey’ & ‘Zoe’ are the inputs,
then the
output will be ‘Welcome Chloe! Welcome Zoe! Welcome Joey too!’
SOLUTION
import java.util.Scanner;
if (a == b && b == c) {
result = 20;
} else if (a == b || b == c || a == c) {
result = 10;
} else {
result = 0;
}
}
}
You need to create a package containing a total of goal kilos of
chocolate. You have two types of chocolate bars available:
Small bars, each weighing 1 kilo.
Big bars, each weighing 5 kilos.
Your task is to determine how many small bars you will need to
use, assuming you always use the big bars first to reach the
8 Easy
target weight. If it is not possible to exactly match the goal
weight using these bars, return -1.
Sample Input & Output
makeChocolate(small : 4, big : 1, goal : 9) → 4
makeChocolate(small : 4, big : 1, goal : 10) → -1
makeChocolate(small : 4, big : 1, goal : 7) → 2
SOLUTION:
import java.util.Scanner;
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
scanner.close();
int sum = 0;
if (a == 13) {
sum = 0;
} else if (b == 13) {
sum = a;
} else if (c == 13) {
sum = a + b;
} else {
sum = a + b + c;
System.out.println(sum);
}
}
You are given three integers: a, b, and c. Your task is to return
the sum of their values after rounding each of them to the
nearest multiple of 10, based on the following rules:
1. If the rightmost digit of a number is 5 or more, round it
10 Easy
up to the next multiple of 10.
2. If the rightmost digit is less than 5, round the number
down to the previous multiple of 10.
For example:
15 rounds up to 20.
12 rounds down to 10.
Return the sum of the rounded values of a, b, and c.
Sample Input & Output
roundSum(a : 16, b : 17, c : 18) → 60
roundSum(a : 12, b : 13, c : 14) → 30
roundSum(a: 6, b : 4, c : 4) → 10
SOLUTION:
import java.util.Scanner;
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
scanner.close();
if (remainder >= 5) {
return num + (10 - remainder); } else {
return num - remainder;
}
}
}