Input / Output

Here are 20 problem statements that test your knowledge of console input/output in Java:

  1. Print Message: Write a Java program to print "Hello, World!" to the console.

  2. Read Integer: Prompt the user to enter an integer and then print it back to the console.

  3. Read Double: Prompt the user to enter a double value and then print it back to the console.

  4. Read String: Prompt the user to enter their name and then print a greeting message with their name.

  5. Read Multiple Integers: Prompt the user to enter three integers separated by spaces and then print their sum.

  6. Read Multiple Doubles: Prompt the user to enter three double values separated by commas and then print their average.

  7. Read Character: Prompt the user to enter a single character and then print it back to the console.

  8. Read Line: Prompt the user to enter a sentence and then print the sentence in uppercase letters.

  9. Read Boolean: Prompt the user to enter a boolean value (true/false) and then print it back to the console.

  10. Read Array: Prompt the user to enter five integers separated by spaces and then print the array in reverse order.

  11. Read Matrix: Prompt the user to enter elements of a 3x3 matrix and then print the matrix.

  12. Read Password: Prompt the user to enter a password (without displaying it) and then print "Access Granted" if the password is correct.

  13. Read File Path: Prompt the user to enter a file path and then print the name of the file.

  14. Read Age: Prompt the user to enter their age and then print "You are a minor" if the age is less than 18, otherwise print "You are an adult".

  15. Read Name and Age: Prompt the user to enter their name and age, then print a message with their name and whether they are a minor or an adult.

  16. Read Multiple Strings: Prompt the user to enter three words separated by commas and then print them in alphabetical order.

  17. Read Two Numbers: Prompt the user to enter two numbers separated by a space, then print their sum, difference, product, and quotient.

  18. Read Decimal Number: Prompt the user to enter a decimal number and then print its square root.

  19. Read Date: Prompt the user to enter a date in the format "DD/MM/YYYY" and then print it in the format "Month DD, YYYY".

  20. Read Color: Prompt the user to enter a color (red, green, blue) and then print a message based on the color (e.g., "You chose red").

  21. Basic Input/Output: Prompt the user to enter their name and age, then print a greeting message with their name and age.

  22. Read and Display Array: Prompt the user to enter five numbers separated by spaces, store them in an array, and then print the array.

  23. Calculate Area: Prompt the user to enter the radius of a circle, calculate the area, and print the result.

  24. User Authentication: Ask the user to enter a username and password. If the username is "admin" and the password is "password123", print "Access granted"; otherwise, print "Access denied".

  25. Calculate Discount: Prompt the user to enter the price of an item and the discount percentage. Calculate the discounted price and print it.

  26. Temperature Conversion: Prompt the user to enter a temperature in Celsius, convert it to Fahrenheit, and print the result.

  27. String Manipulation: Prompt the user to enter a string, convert it to uppercase, and print the result.

  28. Calculate GPA: Prompt the user to enter grades for three subjects, calculate the GPA, and print it.

  29. Find Maximum and Minimum: Prompt the user to enter five numbers separated by spaces, find and print the maximum and minimum numbers.

  30. Check Prime Number: Prompt the user to enter a number, check if it's prime, and print "Prime" or "Not Prime" accordingly.

  31. Reverse String: Prompt the user to enter a string, reverse it, and print the result.

  32. Shopping Cart: Implement a simple shopping cart where the user can enter the name and price of items until they enter "done". Print the total cost.

  33. Count Characters: Prompt the user to enter a sentence, count the number of characters (excluding spaces), and print the count.

  34. Generate Multiplication Table: Prompt the user to enter a number, generate its multiplication table from 1 to 10, and print it.

  35. Factorial Calculation: Prompt the user to enter a number, calculate its factorial, and print the result.

  36. Check Palindrome: Prompt the user to enter a word, check if it's a palindrome, and print "Palindrome" or "Not Palindrome" accordingly.

  37. Sorting Array: Prompt the user to enter five numbers separated by spaces, sort them in ascending order, and print the sorted array.

  38. Binary to Decimal Conversion: Prompt the user to enter a binary number, convert it to decimal, and print the result.

  39. Word Count: Prompt the user to enter a paragraph, count the number of words, and print the count.

  40. Create Calendar: Prompt the user to enter a month and year, then print the calendar for that month.

These problem statements cover a wide range of scenarios, from simple input/output tasks to more complex calculations and manipulations.

Last updated