Practice 70 Java Data Types Programming Questions, TechnoVlogs

Practice 70 Java Data Types Programming Questions


Q1. Write a Java program to declare and initialize all primitive data types and print their default values.
  Expected Output:  
  Default values: 
  byte: 0
  short: 0
  int: 0
  long: 0
  float: 0.0
  double: 0.0
  char: 
  boolean: false

Q2. Write a Java program to demonstrate the use of type casting from `int` to `double`.
  Input:  
  Enter an integer: 10

  Expected Output:     
  Integer: 10
  Converted to double: 10.0

Q3. Write a Java program to convert a `double` value to `int`.
  Input:  
  Enter a double value: 10.99

  Expected Output:     
  Double value: 10.99
  Converted to integer: 10

Q4. Write a Java program to find the size of each primitive data type in Java using the `Byte.SIZE` and related constants.
  Expected Output:  
  byte: 8 bits
  short: 16 bits
  int: 32 bits
  long: 64 bits
  float: 32 bits
  double: 64 bits
  char: 16 bits
  boolean: 1 bit

Q5. Write a Java program to add two integer variables and print the sum.
  Input:  
  Enter first integer: 10  
  Enter second integer: 20

  Expected Output:     
  Sum: 30

Q6. Write a Java program to demonstrate the implicit type promotion in expressions.
  Input:  
  Enter a byte value: 10  
  Enter an int value: 100

  Expected Output:     
  Result of addition (byte + int): 110

Q7. Write a Java program to check the maximum and minimum values of `int` data type.
  Expected Output:  
  Integer MAX value: 2147483647
  Integer MIN value: -2147483648

Q8. Write a Java program to find the ASCII value of a character.
  Input:  
  Enter a character: A

  Expected Output:     
  ASCII value of 'A': 65

Q9. Write a Java program to demonstrate the usage of `float` and `double` data types in a division operation.
  Input:  
  Enter two numbers: 5, 2

  Expected Output:     
  Float result: 2.5
  Double result: 2.5

Q10. Write a Java program to convert a `char` to its numeric value using type casting.
  Input:  
  Enter a character: 9

  Expected Output:     
  Numeric value of character '9': 57

Q11. Write a Java program to perform arithmetic operations on two `float` variables.
  Input:  
  Enter first float: 5.5  
  Enter second float: 2.2

  Expected Output:     
  Sum: 7.7  
  Difference: 3.3  
  Product: 12.1  
  Quotient: 2.5

Q12. Write a Java program to print a Unicode character using its code point.
  Input:  
  Enter Unicode code point: 65

  Expected Output:     
  Unicode character: A

Q13. Write a Java program to demonstrate the difference between `float` and `double` precision.
  Input:  
  Enter a number: 1.123456789

  Expected Output:     
  Float: 1.1234568  
  Double: 1.123456789

Q14. Write a Java program to demonstrate the overflow of `byte` data type.
  Expected Output:  
  Byte value before overflow: 127  
  Byte value after overflow: -128

Q15. Write a Java program to check if a `char` is a digit or a letter using `Character` methods.
  Input:  
  Enter a character: 5

  Expected Output:  
  Is digit: true  
  Is letter: false

Q16. Write a Java program to demonstrate the use of the `boolean` data type.
  Input:  
  Enter a boolean value: true

  Expected Output:     
  Boolean value: true

Q17. Write a Java program to convert a `String` to `int` and print the result.
  Input:  
  Enter a string: 123

  Expected Output:     
  Converted integer: 123

Q18. Write a Java program to calculate the area of a rectangle using `float` data type for dimensions.
  Input:  
  Enter length: 5.5  
  Enter width: 3.2

  Expected Output:     
  Area of the rectangle: 17.6

Q19. Write a Java program to check if a number is divisible by both 5 and 3 using `int` data type.
  Input:  
  Enter a number: 15

  Expected Output:     
  The number is divisible by both 5 and 3: true

Q20. Write a Java program to find the square of a `double` number.
  Input:  
  Enter a number: 4.5

  Expected Output:     
  Square of the number: 20.25

Q21. Write a Java program to display the current system time in milliseconds using `long` data type.
  Expected Output:  
  Current time in milliseconds: 1625248930000

Q22. Write a Java program to check if a character is a lowercase letter using `Character` methods.
  Input:  
  Enter a character: a

  Expected Output:     
  Is lowercase: true

Q23. Write a Java program to find the average of three `int` numbers.
  Input: 
  Enter first number: 10  
  Enter second number: 20  
  Enter third

  Input:  
  Enter first number: 10  
  Enter second number: 20  
  Enter third number: 30

  Expected Output:     
  Average: 20

Q24. Write a Java program to demonstrate the use of the `long` data type for storing large numbers.
  Input:  
  Enter a long number: 1234567890123

  Expected Output:     
  Long number: 1234567890123 

Q25. Write a Java program to perform division of two integers and display the quotient and remainder.
  Input:  
  Enter first number: 15  
  Enter second number: 4

  Expected Output:     
  Quotient: 3  
  Remainder: 3

Q26. Write a Java program to convert a `boolean` value to its string equivalent.
  Input:  
  Enter a boolean value: true

  Expected Output:     
  Boolean as String: true

Q27. Write a Java program to check if a number is positive, negative, or zero using `int` data type.
  Input:  
  Enter a number: -5

  Expected Output:     
  The number is negative

Q28. Write a Java program to check if a given `char` is a digit or a special character.
  Input:  
  Enter a character: #

  Expected Output:     
  The character is a special character.

Q29. Write a Java program to convert a `String` containing a floating-point number to `float`.
  Input:  
  Enter a string: 12.34

  Expected Output:     
  Converted float value: 12.34

Q30. Write a Java program to find the cube of a `double` number.
  Input:  
  Enter a number: 3.0

  Expected Output:     
  Cube of the number: 27.0

Q31. Write a Java program to check the maximum and minimum values of `short` data type.
  Expected Output:  
  Short MAX value: 32767  
  Short MIN value: -32768

Q32. Write a Java program to perform addition and multiplication using `int` data type.
  Input:  
  Enter first number: 5  
  Enter second number: 7

  Expected Output:     
  Sum: 12  
  Product: 35

Q33. Write a Java program to demonstrate the type promotion in arithmetic operations with `byte`, `short`, and `int`.
  Input:  
  Enter first byte value: 5  
  Enter second short value: 15

  Expected Output:     
  Result of addition: 20

Q34. Write a Java program to calculate the perimeter of a rectangle using `float` data type.
  Input:  
  Enter length: 8.5  
  Enter width: 3.2

  Expected Output:     
  Perimeter of the rectangle: 23.4

Q35. Write a Java program to demonstrate the precision loss when converting from `double` to `float`.
  Input:  
  Enter a double value: 12.3456789

  Expected Output:     
  Double: 12.3456789  
  Float (after conversion): 12.345679

Q36. Write a Java program to convert a `long` to `int` and display the result.
  Input:  
  Enter a long value: 10000000000

  Expected Output:     
  Converted int value: 1410065408

Q37. Write a Java program to demonstrate `float` precision in division.
   Input:
  Enter numerator: 5  
  Enter denominator: 2

  Expected Output:     
  Float result: 2.5

Q38. Write a Java program to check if a `boolean` value is true or false.
  Input:  
  Enter a boolean value: false

  Expected Output:     
  The boolean value is: false

Q39. Write a Java program to determine whether a `char` represents a vowel or consonant.
  Input:  
  Enter a character: E

  Expected Output:     
  The character is a vowel.

Q40. Write a Java program to demonstrate the difference between `double` and `float` in precision.
  Input:  
  Enter a number: 7.123456789

  Expected Output:     
  Double: 7.123456789  
  Float: 7.123457

Q41. Write a Java program to demonstrate the use of `char` for storing a character and print its value.
  Input:  
  Enter a character: G

  Expected Output:     
  Character value: G

Q42. Write a Java program to find the product of three `int` values.
  Input:  
  Enter first number: 2  
  Enter second number: 3  
  Enter third number: 4

  Expected Output:     
  Product: 24

Q43. Write a Java program to check if a `double` value is greater than or equal to a given threshold.
  Input:  
  Enter a double value: 4.5  
  Enter a threshold: 3.0

  Expected Output:     
  The value is greater than or equal to the threshold.

Q44. Write a Java program to calculate the simple interest using `float` values for principal, rate, and time.
  Input:  
  Enter principal amount: 10000  
  Enter rate of interest: 5  
  Enter time in years: 2

  Expected Output:     
  Simple interest: 1000.0

Q45. Write a Java program to find the length of a `String` and its character at a specified index using `charAt()` method.
  Input:  
  Enter a string: Hello

  Expected Output:     
  Length of the string: 5  
  Character at index 1: e

Q46. Write a Java program to convert an integer to a string using `String.valueOf()` method.
  Input:  
  Enter an integer: 123

  Expected Output:     
  Converted string: 123

Q47. Write a Java program to perform modulus operation on two `int` values and display the result.
  Input:  
  Enter first number: 10  
  Enter second number: 3

  Expected Output:     
  Remainder: 1

Q48. Write a Java program to find the average of an array of `double` values.
  Input:  
  Array: {2.5, 3.5, 4.0}

  Expected Output:     
  Average: 3.3333335

Q49. Write a Java program to calculate the area of a circle using `double` data type for radius.
  Input:  
  Enter radius: 5.5

  Expected Output:     
  Area of the circle: 95.03318

Q50. Write a Java program to convert a `String` containing a `boolean` value to a `boolean`.
  Input:  
  Enter a string: true

  Expected Output:     
  Converted boolean value: true

Q51. Write a Java program to find the cube root of a `double` number.
  Input:  
  Enter a number: 27.0

  Expected Output:     
  Cube root: 3.0

Q52. Write a Java program to demonstrate automatic type promotion in expressions with `byte` and `char`.
  Input:  
  Enter a byte value: 5  
  Enter a char value: 10

  Expected Output:     
  Result: 15

Q53. Write a Java program to check if a given number is even or odd using `int` data type.
  Input:  
  Enter a number: 4

  Expected Output:     
  The number is even.

Q54. Write a Java program to find the maximum of three `int` numbers.
  Input:  
  Enter first number: 5  
  Enter second number: 10  
  Enter third number: 7

  Expected Output:     
  Maximum number: 10

Q55. Write a Java program to find the minimum of three `double` numbers.
  Input:  
  Enter first number: 3.5  
  Enter second number: 4.0  
  Enter third number: 2.5

  Expected Output:     
  Minimum number: 2.5

Q56. Write a Java program to convert a `double` value to an `int` using explicit casting.
  Input:  
  Enter a double value: 10.99

  Expected Output:     
  Converted integer value: 10

Q57. Write a Java program to check if a given number is divisible by 7 using `int` data type.
  Input:  
  Enter a number: 14

  Expected Output:     
  The number is divisible by 7.

Q58. Write a Java program to calculate the perimeter of a triangle using `double` data type for sides.
  Input:  
  Enter side1: 3.0  
  Enter side2: 4.0  
  Enter side3: 5.0

  Expected Output:     
  Perimeter of the triangle: 12.0

Q59. Write a Java program to display the reverse of a `String` using `charAt()` method.
  Input:  
  Enter a string: Hello

  Expected Output:     
  Reversed string: olleH

Q60. Write a Java program to demonstrate the usage of `boolean` values in logical operations.
  Input:  
  Enter first boolean value: true  
  Enter second boolean value: false

  Expected Output:     
  AND operation result: false  
  OR operation result: true

Q61. Write a Java program to perform a type conversion from `int` to `byte`.
  Input:  
  Enter an integer: 300

  Expected Output:     
  Converted byte value: 44

Q62. Write a Java program to calculate the area of a triangle using `float` data type for base and height.
  Input:  
  Enter base: 6.5  
  Enter height: 4.5

  Expected Output:     
  Area of the triangle: 14.625

Q63. Write a Java program to find the remainder when one `double` is divided by another.
  Input:  
  Enter numerator: 10.5  
  Enter denominator: 3.2

  Expected Output:     
  Remainder: 0.9

Q64. Write a Java program to check if a `long` value is even or odd.
  Input:  
  Enter a long number: 1234567890123

  Expected Output:     
  The number is odd.

Q65. Write a Java program to find the product of two `double` numbers.
  Input:  
  Enter first number: 2.5  
  Enter second number: 3.4

  Expected Output:     
  Product: 8.5

Q66. Write a Java program to demonstrate the effect of `char` values in mathematical operations.
  Input:  
  Enter a character: A

  Expected Output:     
  Numeric value of 'A': 65

Q67. Write a Java program to find the sum of an array of `int` values.
  Input:  
  Array: {1, 2, 3, 4}

  Expected Output:     
  Sum: 10

Q68. Write a Java program to calculate the circumference of a circle using `double` data type.
  Input:  
  Enter radius: 7.0

  Expected Output:     
  Circumference: 43.9823

Q69. Write a Java program to demonstrate the use of `long` data type to store large numbers.
  Input:  
  Enter a long number: 99999999999

  Expected Output:     
  Long number: 99999999999

Q70. Write a Java program to find the absolute value of a number using `Math.abs()` method.
  Input:  
  Enter a number: -20

  Expected Output:     
  Absolute value: 20

Social Share

Bikki Singh Instructor TechnoVlogs

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!