Top 100 Java Programs

    public class HelloWorld { public static void main(String[] args) { System.out.println(“Hello World!”); } } Output: Hello World!

    public class VariablesInitialization { public static void main(String[] args) { // TODO code application logic here boolean flag=true; System.out.println(flag); System.out.println(“Flag=”+flag); […]

    public class JavaOperators { public static void main(String args[]) { System.out.println(“Example 1:——————————-“); //Java Unary Operator Example: ++ and — int […]

    °C = (°F – 32) / (9/5) import java.util.Scanner; public class JavaFarenheitToCelsius { public static void main(String[] args) { float […]

    import java.util.Scanner; public class JavaMarksAverage { public static void main(String[] args) { int math,english,science,art,computer,total,percent; Scanner sc=new Scanner(System.in); System.out.println(“Enter marks out […]

    Simple Interest = (Princple * Rate * Time)/100 import java.util.Scanner; public class JavaSimpleInterest { public static void main(String[] args) { […]

    Area of Circle = (22/7) X radius x radius import java.util.Scanner; public class JavaFindAreaCircle { public static void main(String[] args) […]

    Area of Rectangle= Length X Breadth import java.util.Scanner; public class JavaFindAreaRectangle { public static void main(String[] args) { int l,b,area; […]

    public class JavaSwap { public static void main(String[] args) { int a=10, b=20, temp; System.out.println(“Before swapping”); System.out.println(“value of a=”+a); System.out.println(“value […]

    public class JavaSwapWithTwoVars { public static void main(String[] args) { int a=10, b=20; System.out.println(“Before swapping”); System.out.println(“value of a=”+a); System.out.println(“value of […]

    public class JavaIncrementDecrementOperator { public static void main(String[] args) { int i=10,j=10,num=0; System.out.println(“i=”+i); System.out.println(“j=”+j); System.out.println(“num=”+num); System.out.println(“—————————————“); i++; j–; System.out.println(“i=”+i); System.out.println(“j=”+j); […]

    public class DuplicateWord { public static void main(String[] args) { String string = “Big black bug bit big bug black […]

    import java.util.Scanner; public class DigitToWord { public static void main(String[] args) { // TODO code application logic here int r, […]

    import java.util.*; public class BinarySearch { public static void main(String[] args) { int n, lb, ub, mid, pos = -1; […]

    import java.util.Scanner; public class EqualNumber { public static void main(String[] args) { int n; Scanner sc = new Scanner(System.in); System.out.print(“Enter […]

    import java.util.Scanner; public class EvenOdd { public static void main(String[] args) { int number; Scanner sc = new Scanner(System.in); System.out.print(“Enter […]

    import java.util.Scanner; public class GreaterNumber { public static void main(String[] args) { int n1, n2; Scanner sc = new Scanner(System.in); […]

    import java.util.Scanner; public class GreatestNumber { public static void main(String[] args) { int n1, n2, n3; Scanner sc = new […]

    import java.util.Scanner; public class LeapYear { public static void main(String[] args) { int year; Scanner sc = new Scanner(System.in); System.out.print(“Enter […]

    import java.util.Scanner; public class PassingDivision { public static void main(String[] args) { // TODO code application logic here int math, […]

    A person can votes if age is greater than or equal to 18. import java.util.Scanner; public class VotingAge { public […]

    public class JavaOperators { public static void main(String args[]) { System.out.println(“Example 1:——————————-“); // Java Unary Operator Example: ++ and — […]

    A positive number is called armstrong number if it is equal to the sum of cubes of its digits. Examples: […]

    An Automorphic number is a number whose square “ends” in the same digits as the number itself. Examples: 5*5 = […]

    A number is said to be Buzz Number if it ends with 7 or is divisible by 7. Example: 1007 […]

    A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically […]

    Two integers a and b are said to be relatively prime, mutually prime, or coprime if the only positive integer […]

    import java.util.Scanner; public class DigitToWord { public static void main(String[] args) { // TODO code application logic here int r, […]

    A Duck number is a number which has zeroes present in it, but there should be no zero present in […]

    Factorial is the product of all positive integers less than or equal to n. Examples: 4! = 4 × 3 […]

    Factors of 24: 1, 2, 3, 4, 6, 8, 12, 24. import java.util.Scanner; public class Factors { public static void […]

    A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. […]

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 public class FloydTriangle { public […]

    the greatest common divisor (gcd) of two or more integers, which are not all zero, is the largest positive integer […]

    import java.util.Scanner; public class HappyNumber { public static void main(String[] args) { int n, r = 1, num, sum = […]

    import java.util.Scanner; public class HarshadNumber { public static void main(String[] args) { int r, n, num, sum = 0; Scanner […]

    import java.util.Scanner; public class LCMProgram { public static void main(String[] args) { int a, b, gcd = 1, lcm = […]

    import java.util.Scanner; public class MultiplyOfDigit { public static void main(String[] args) { // TODO code application logic here int r, […]

    import java.util.Scanner; public class NeonNumber { public static void main(String[] args) { // TODO code application logic here int n, […]

    import java.util.Scanner; public class NivenNumber { public static void main(String[] args) { // TODO code application logic here int n, […]

    import java.util.Scanner; public class PalindromeNumber { public static void main(String[] args) { int n, num, r, rev = 0; Scanner […]

    import java.util.Scanner; public class PerfectNumber { public static void main(String[] args) { // TODO code application logic here int n, […]

    import java.util.Scanner; public class PrimeNumber { public static void main(String[] args) { // TODO code application logic here int n, […]

    import java.util.Scanner; public class ReverceNumber { public static void main(String[] args) { // TODO code application logic here int n, […]

    import java.util.Scanner; public class SpecialNumber { public static void main(String[] args) { // TODO code application logic here int n, […]

    import java.util.Scanner; public class SpyNumber { public static void main(String[] args) { // TODO code application logic here int r, […]

    import java.util.Scanner; public class SumofDigits { public static void main(String[] args) { // TODO code application logic here int r, […]

    import java.util.Scanner; public class TwinPrime { public static void main(String[] args) { int a, b; Scanner sc = new Scanner(System.in); […]

    import java.util.Scanner; public class TwistedPrime { public static void main(String[] args) { // TODO code application logic here int n, […]

    import java.util.Scanner; public class UniqueNumber { public static void main(String[] args) { // TODO code application logic here int r1, […]

    import java.util.Scanner; public class NameOfDay { public static void main(String[] args) { int day; Scanner sc=new Scanner(System.in); System.out.print(“Enter day=”); day=sc.nextInt(); […]

    import java.util.Scanner; public class Menu { public static void main(String[] args) { int choice; double area; int l,b; int a; […]

    import java.util.Scanner; public class VowelsCharacter { public static void main(String[] args) { char ch; Scanner sc=new Scanner(System.in); System.out.print(“Enter Character=”); ch=sc.next().charAt(0); […]

    import java.util.Scanner; public class NameOfMonth { public static void main(String[] args) { int month; Scanner sc = new Scanner(System.in); System.out.print(“Enter […]

    public class Pattern1 { public static void main(String[] args) { for (int i = 1; i

    public class Pattern11 { public static void main(String[] args) { for (int i = 5; i >= 1; i–) { […]

    public class Pattern21 { public static void main(String[] args) { for (int i = 1; i = 1; j–) { […]

    public class Pattern31 { public static void main(String[] args) { for (int i = 1; i = 1; j–) { […]

    public class Pattern34 { public static void main(String[] args) { for (int i = 5; i >= 1; i–) { […]

    public class Pattern37 { public static void main(String[] args) { for (int i = 1; i = 1; j–) { […]

    import java.util.Scanner; public class NumberSeries { public static void main(String[] args) { int n, sum = 0; Scanner sc = […]

    import java.util.Scanner; public class EvenNumberSeries { public static void main(String[] args) { int n, sum = 0; Scanner sc = […]

    import java.util.Scanner; public class OddNumberSeries { public static void main(String[] args) { int n, sum = 0; Scanner sc = […]

    import java.util.Scanner; public class SquareNumberSeries { public static void main(String[] args) { int n,sum=0; Scanner sc = new Scanner(System.in); System.out.print(“Enter […]

    import java.util.Scanner; public class SquarePostNumberSeries { public static void main(String[] args) { int n,sum=0; Scanner sc = new Scanner(System.in); System.out.print(“Enter […]

    import java.util.Scanner; public class SquarePreNumberSeries { public static void main(String[] args) { int n,sum=0; Scanner sc = new Scanner(System.in); System.out.print(“Enter […]

Recent Posts