ADVERTISEMENT
ADVERTISEMENT

Java Basic Programs

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 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. 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.
  15. 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)?
  16. 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.
  17. 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?
  18. 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.
  19. 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.
  20. 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.
  21. 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.
  22. 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.
  23. 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.
  24. 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.
  25. 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.
  26. 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.
  27. 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.
  28. 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.
  29. 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.
  30. 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.
  31. 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.
  32. 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.
  33. 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.
  34. 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?
  35. 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?
  36. 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.
  37. 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.
  38. 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.
  39. 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!
  40. 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.
  41. 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.
  42. 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).
  43. 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.
  44. 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).
  45. 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.
  46. 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.
  47. Java program to check Harshad Number
    In this java program, we are going to check whether a given number is Harshad Number or not.
  48. Java program to check Pronic Number
    In this java program, we are going to check whether a given number is Pronic Number or not.
  49. 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.
  50. 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.
  51. Java program to swap two numbers using function
    In this program we will swap integer numbers using function, we will design a function to swap two numbers.
  52. Java program to check number is positive, negative or zero
    Check positive, negative and zero in java: In this java program, we will read and integer number and check whether it is positive, negative or zero.
  53. Java program to find largest number among three numbers
    Find largest number from three integer number in Java: This program will read three integer number from the keyboard and find the largest number.
  54. Java program to check whether year is Leap year or not
    Here, we are going to learn how to check whether a given year is leap year or not using Java program?
  55. Java program to demonstrate example of enum data type
    Enum data type example in Java: In this program, we will learn how enum is declared and how it will be used in a java program?
  56. Java program to demonstrate example of this keyword
    This program will demonstrate use of this keyword, in this program we will see what will happen if we do not use this keyword even actual and formal arguments of the methods are same and what will happen if we will use this.
  57. Java example for while loop demonstration
    This program will demonstrate example of while loop in java, the use of while is similar to c programming language, here we will understand how while loop works in java programming with examples.
  58. Java example for do while loop demonstration
    This program will demonstrate example of do while loop in java, the use of do while is similar to c programming language, here we will understand how do while loop works in java programming with examples.
  59. Java program to Calculate the Compound Interest
    In this code snippet we will learn how to calculate compound interest.
  60. Java program to find the Greatest Common Divisor or Euclidean Algorithm Program or Highest Common Divisor.
    In this code snippet we will learn how to get Greatest Common Divisor in Java, Implementation of Euclidean Algorithm to get Highest Common Divisor.
  61. Java program to find the Greatest Common Factor or Euclidean Algorithm Program or Highest Common Factor.
    In this code snippet we will learn how to get Greatest Common Factor in Java, Implementation of Euclidean Algorithm to get Highest Common Factor.
  62. Java program to Calculate LCM (Least Common Multiple)
    In this code snippet, we will find the LCM of given numbers using Java program.
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.