C C++ Java Data Structure Python JavaScript CSS Ajax PL/SQL PHP Puzzles C programs C++ programs Java programs



Home » Java solved programs

Java Basic Input Output Programs, Examples






This section contains solved programs of Java Basic Input, Output programs with basic mathematical, conditional statements and looping concepts.

All programs have explanation, output on different inputs.

List of Java Basic I/O Example Programs

Find some of the programs (which are popular and most searched on the web) with source code, explanation and output.

  1. Java program to print "Hello world" (First program in Java).
    Learn: How to write, compile and execute our first program in Java, in this program we will print some text (Hello World) on the screen.
  2. How to print different type of values in Java?
    Here, we will learn how to print different type of values using Java program? In this program, we will declare and define different variables with values and print them.
  3. How to read and print an integer value in Java?.
    Through this program, we will learn how to read (input) an integer number from user and print the input value on the output screen?
  4. Java program to find sum and average of two integer numbers.
    This is a simple java program, in which we are taking input of two integer numbers and calculate their SUM and AVERAGE.
  5. Java Program to find square, cube and square root of a given number.
    Math.pow() amd Math.sqrt() Methods in Java: In this program, we will take an integer number will find their Square, Cube and Square Root of given number through these methods?
  6. Java program to check whether input number is EVEN or ODD.
    Check EVEN or ODD in Java: In this program, we will input an integer number and check whether it is EVEN or ODD.
  7. Java program to swap two numbers with and without using third variable.
    Swap two integer numbers in Java: Here, we will input two integer numbers and swap them through two methods 1) Using third variable and 2) without using third variable.
  8. Java program to print uppercase and lowercase alphabets.
    In this java program, we are going to print uppercase and lowercase alphabets from A to Z and a to z using loop, it’s a very simple program demonstrating use of lopping with alphabets as loop counter.
  9. Java program to print Christmas tree.
    In this java program, we are going to learn how to print a Christmas tree? By using nested looping and basic concept, we are printing the tree using stars.
  10. Java program to print a rectangle using stars (java pattern program).
    In this java program, we are going to learn how to print a stars pattern to make a rectangle by using stars?
  11. Java program to print the diamond shape of stars.
    In this java program, we are going to learn how to print the diamond shape of stars?
  12. Java program to print pattern of alphabets.
    In this java program, we are going to print pattern of alphabets? Here, we are taking input for number of rows and printing the pattern according to input.
  13. Java program to print Pascal's triangle.
    In this java program, we are going to read number of rows and printing Pascal’s triangle according to the input.
  14. 


  15. Java program to generate permutation and combination of the numbers.
    In this java program, we are going to generate permutation and combination of the numbers.
  16. Java program to print all Armstrong numbers between given range.
    In this Java program, we are going to learn how to check and print all Armstrong number between given range (from starting number to end number)?
  17. Java program to count total positives, negatives and zeros from an array.
    In this java program, we are going to count total number of negative, positive and zero elements in a given array of integers.
  18. Java program to find sum of all digits.
    In this Java program, we are going to learn how to find sum of all digits? Here, we are reading an integer number and finding sum of its all digits.
  19. Java program to find mean of a given number.
    In this java program, we are going to learn how to read N numbers and find the mean of all input number?
  20. Java program to build a calculator.
    In this java program, we are writing code for a simple calculator. Here, we are performing multiple basic mathematical tasks using switch case statement and do while loop.
  21. Java program to calculate compound interest.
    In this java program, we are going to learn how to calculate compound interest. Here, we are reading principle, rate and time and calculating compound interest.
  22. Java program to read strings with different methods.
    In this article, we are going to read string with two different methods StringReader and Scanner class with example, output and explanation.
  23. How to get length of the string in java?
    In this java program, we are going to take string as an input and get the length of the string, to read a string as an input, we are using ‘nextLine()’ method of ‘string’ class.
  24. Java program to validate input as integer value only.
    In this java program, we are going to learn how to validate user input? Here, we are reading an integer value, if someone’s input is not an integer it will through an error and reads the value again.
  25. Java program to print spiral pattern of the given input.
    In this java program, we are going to learn how to print a spiral pattern of the numbers, according to the given input.
  26. Java program to check whether a given character is alphabet or not.
    In this java program, we will learn how to check whether a given character in an alphabet or not? Here, we are reading a character from the user and validating it is alphabet or not.
  27. Java program to print pattern of numbers in triangle and reverse trainable form.
    In this java program, we are implementing a program that will print a trainable in normal and reverse order using numbers.
  28. Java program to print Floyd’s triangle till given N rows.
    In this java program, we are going to print a pattern that is known as Floyd’s triangle till N rows. Here, we are taking N from the user and printing the pattern according to it.
  29. Java program to convert string to Boolean.
    In this java program, we are going to learn how to convert a string value to Boolean value? Here, we are taking an input as string and converting it into Boolean value.
  30. Java program to print ‘W’ pattern using stars.
    Here, we are implementing a java program that will print a pattern like ‘W’ alphabet using stars. It is a pattern printing program in java.
  31. Java program to count factors of a given number.
    Here, we are implementing a java program that will read an integer number and count its all factors. If a number is divisible by 4 different numbers than factors of that number will be 4.
  32. 


  33. Program to verify answers of answer sheets of N students in Java.
    Here, we are implementing a java program that will read number of students their answers which they marked in answer sheets, answer key (correct answers) and finally calculate the result of all students.
  34. Java program to compare two numbers with each other.
    Here, we are implementing a java program that will read two integer number and compare them each other. Program will print which is smallest, largest and equal (if they are) number.
  35. Java program to calculate area of Hexagon.
    Here, we are implementing a java program, in which we calculate the area of Hexagon. This will be calculated based on given length of the sides.
  36. Java program to print prime numbers between given range.
    Here, we are implementing java program that will read a minimum and maximum number and print the all prime numbers between the given range.
  37. Java program to print patterns (2 Examples based on numbers pattern)
    Here, we are implementing two java programs that will print two different patterns based on given input; input will be the numbers of rows to print in the patterns.
  38. Java program to find perimeter of a rectangle.
    In this java program, we are going to find perimeter of a rectangle, to find perimeter we need to take length and width as an input.
  39. Java program to generate random numbers between given ranges.
    Here, we are implementing a java program that will generate and print random numbers between given ranges?
  40. Java program to check whether a given number is ugly number or not.
    Here, we are implementing a java program that will read an integer number and check whether it is an ugly number or not?
  41. Java program to check whether given number is Kaprekar number or not.
    Here, we are going to implementing a java program that will read an integer number and check whether it is Kaprekar number or not.
  42. Java program to find cube 1 to N.
    In this java program we are going to find the cube from 1 to N, where N will we the user input.
  43. Java program to find the Length of Longest Sequence of 0’s in binary form of a number.
    In this java program we are going to find the longest sequence of 0’s of binary form of a number.
  44. Java program to find sum of factorials from 1 to N.
    Here, we are implementing a java program that will read the value of N and find sum of the factorials from 1 to N. It is a solution of series 1! + 2! + 3! + 4! + ... N!
  45. Java program to find the correct output of student quiz.
    Here, we are implementing a java program that will be used to find the correct output of given student quiz.
  46. Java program to check whether Emrip number.
    Here, we are implementing a java program that will read a number and check whether it is Emrip number or not.
  47. Java program to find occurrences of palindrome words in a string.
    Here, we are implementing a java program that will read a string and check the palindrome words in string also find the occurrences of words in a given string.
  48. Java program to count number of notes (rupees) in given amount.
    Here, we are implementing a java program that will read an amount and then convert, count total number of different notes (rupees).
  49. Java program to swap first and last character of each word in a string.
    Here, we are implementing a java program that will read a string and we have to swap first and last character of each word in given string.
  50. Java program to read marks between 1 to 100 (An Example of Exceptional Handling).
    An Example of Exceptional Handing: In this java program we are implement a program in which we are reading marks of a student between 1 to 100 and if marks are out of range exceptional will be returns.
  51. Java program to divide two numbers and catch the exception, if divisor is 0.
    In this java program, we are reading two integer numbers and dividing them also checking the exception. Program will through an error if second number (divisor) will be zero (0).
  52. Java program to handle multiple exceptions.
    Java multiple exceptional handling example: In this java program, we are reading two integer numbers, dividing them and handling exceptions.
  53. Java program to check Evil number.
    In this java program, we are going to write code to check whether a given number is an Evil number or not.
  54. Java program to check Harshad Number.
    In this java program, we are going to check whether a given number is Harshad Number or not.
  55. Java program to check Pronic Number.
    In this java program, we are going to check whether a given number is Pronic Number or not.
  56. Java program to check whether the number is IMEI Number or not.
    In this java program, we will read a number, which will be an IMEI number of a mobile and check whether it is a valid IMEI number or not.
  57. Java program to find smallest element in an array.
    In this java program, we are reading an integer array of N elements and finding smallest element among them.
  58. Java program to find second smallest element in an array.
    In this java program, we are reading an integer array of N elements and finding second smallest element among them.
  59. Java program to find second largest element in an array.
    In this java program, we are reading an integer array of N elements and finding second largest element among them.
  60. Java program to convert given number of seconds to hours, minutes and second.
    In this java program, we are reading number of seconds from the user and converting the seconds into hours, minutes and seconds and printing in HH:MM:SS format.
  61. Java program to swap two numbers using function.
  62. Java program to check number is positive, negative or zero.
  63. Java program to find largest number among three numbers.
  64. Java program to check whether year is Leap year or not.
  65. Java program to demonstrate example of enum data type.
  66. Java program to demonstrate example of this keyword.
  67. Java example for while loop demonstration.
  68. Java example for do while loop demonstration.
  69. Java - Calculate Compound Interest using Java Program. (Code Snippet)
  70. Java - Greatest Common Divisor or Euclidean Algorithm Program or Highest Common Divisor. (Code Snippet)
  71. Java - Greatest Common Factor or Euclidean Algorithm Program or Highest Common Factor. (Code Snippet)
  72. Java - Calculate LCM (Least Common Multiple) using Java Program. (Code Snippet)






You may also be interested in...

C/C++ Tips and Tricks...

Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.


Comments and Discussions