Variables and Datatypes

Let's test your knowledge on variables and data types in Java with the following problem statements:

  1. Declare a variable of type int named age and assign it the value 25.

  2. Create a variable of type double named temperature and assign it the value 98.6.

  3. Declare a variable of type boolean named isRaining and assign it the value true.

  4. Create a variable of type char named grade and assign it the value 'A'.

  5. Declare a variable of type String named name and assign it the value "John Doe".

  6. Initialize three variables num1, num2, and num3 of type int with values 10, 20, and 30 respectively.

  7. Create a variable pi of type double and assign it the value of pi (use the Math.PI constant).

  8. Declare a variable isEven of type boolean and assign it the result of checking whether num1 is an even number.

  9. Initialize a variable initial of type char with the initial letter of your first name.

  10. Declare a variable city of type String and assign it the name of your favorite city.

  11. Create a variable isPalindrome of type boolean and assign it the result of checking whether the string "madam" is a palindrome.

  12. Initialize variables length and width of type double with values 5.5 and 2.5 respectively.

  13. Declare a variable isPositive of type boolean and assign it the result of checking whether num2 is positive.

  14. Create a variable greeting of type String and assign it the concatenated string "Hello, " and the value of name.

  15. Initialize a variable totalStudents of type int with the value 100.

  16. Declare a variable isLeapYear of type boolean and assign it the result of checking whether the current year is a leap year.

  17. Create variables price1 and price2 of type double and assign them values 10.50 and 20.75 respectively.

  18. Declare a variable isVowel of type boolean and assign it the result of checking whether the character in grade is a vowel.

  19. Initialize variables hoursWorked and hourlyRate of type double with values 40.5 and 15.0 respectively.

  20. Declare a variable isPrime of type boolean and assign it the result of checking whether num3 is a prime number.

These problems cover a variety of scenarios involving different data types and variable declarations in Java.

Last updated