Top 20 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, […]