LearnFrenzy
Sign in Take a free test

Java Basics, Syntax and Data Types · Exercise 4 of 4

Java Basics, Syntax and Data Types Java Basics Programs

  • 10 questions
  • Page 1 of 1
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Beginner Java programs that use variables, data types, operators, casting and formatted output. Write each one yourself first, then open the solution – every solution was compiled and run on Java 21, and the output shown is the real output.

Question 1 Easy

Read the principal, annual rate and years, and print the simple interest, compound interest (compounded yearly) and the final amounts, formatted to two decimal places.

Question page & discussion
Question 2 Easy

Print a table of Celsius temperatures from -10 to 40 in steps of 10 with their Fahrenheit and Kelvin values, aligned in columns.

Question page & discussion
Question 3 Easy

Read a person's weight in kilograms and height in centimetres, compute the BMI (kg / m²) rounded to one decimal, and print the WHO category.

Question page & discussion
Question 4 Easy

Swap two integers three ways – with a temporary variable, with arithmetic, and with XOR – and print the values after each swap.

Question page & discussion
Question 5 Easy

Read a number of seconds (possibly very large) and print it as days, hours, minutes and seconds, using long arithmetic and / and %.

Question page & discussion
Question 6 Easy

Read an integer and print the number of digits, the sum of its digits, the reversed number and whether it is a palindrome, using only arithmetic.

Question page & discussion
Question 7 Easy

Print the characters '0'–'9' and 'A'–'F' with their decimal, hexadecimal and binary codes, and show the lowercase version of each letter by adding 32.

Question page & discussion
Question 8 Medium

Compute an electricity bill for given units: first 100 units at ₹3.50, next 100 at ₹5.00, next 100 at ₹6.50 and above 300 at ₹8.00, plus a fixed charge of ₹50 and 5% tax; print a breakdown.

Question page & discussion
Question 9 Easy

Print a table of all eight primitive types with their size in bits and their minimum and maximum values, using the wrapper classes' constants.

Question page & discussion
Question 10 Medium

Given parallel arrays of item names, prices and quantities, print an aligned bill with line totals, a 10% discount above ₹1,000, 18% GST and the final amount rounded to the nearest rupee.

Question page & discussion
All exercises doneBack to Java Basics, Syntax and Data TypesRevise the concepts or pick another topic

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links