Category: Example

https://cdn-icons-png.flaticon.com/256/5486/5486145.png

  • Find Maximum of Three Numbers:

    public class MaxOfThreeNumbers {
    
     public static void main(String[] args) {
    
     int num1 = 10, num2 = 20, num3 = 15, max;
    
     max = (num1 > num2) ? (num1 > num3 ? num1 : num3) : (num2 > num3 ? num2 : num3);
    
     System.out.println(“Maximum of ” + num1 + “, ” + num2 + “, and ” + num3 + ” is: ” + max);
    
     }

    Output:

    Maximum of 10, 20, and 15 is: 20
  • Addition of Two Numbers:

    public class AddNumbers {
    
     public static void main(String[] args) {
    
     int num1 = 5, num2 = 10, sum;
    
     sum = num1 + num2;
    
     System.out.println(“Sum of ” + num1 + ” and ” + num2 + ” is: ” + sum);
    
     }

    Output:

    Sum of 5 and 10 is: 15
  • Hello World Program:

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

    Output:

    Hello, World!