Write a programm in java to find maximum of three numbers using conditional operator


Write a programm in java to find maximum of three numbers using conditional operator

import java.util.*;
public class Maximum
{ 
          public static void getMaximum(int a,int b, int c)
          { 
                   int d = c > (a > b ? a : b) ? c : ((a > b) ? a : b);
        System.out.println("Largest Number:"+d);             
          }       

          public static void main(String args[])
          {
                   int a,b,c;               
                   Scanner ob = new Scanner(System.in);
                  
                   System.out.println("Enter the Number A : ");                
                   a = ob.nextInt();                      
                   System.out.println("Enter the Number B : ");                 
                   b = ob.nextInt();                      
                   System.out.println("Enter the Number C : ");                 
                   c = ob.nextInt();                      
                  
                   getMaximum(a,b,c);
                  
          }       
}
OUTPUT:-
Write a programm in java to use wrapper class of each primitive data types

import java.util.*;

public class Wrapper
{
          public static void main(String args[])
          {
                   Scanner KB=new Scanner(System.in);

                   //int-            Integer

                   System.out.println("Enter an Integer:");
                   int n=KB.nextInt();
                   Integer I=new Integer(n);
                   System.out.println(I);

                   //long-                   Long

                   System.out.println("Enter a Long Integer:");
                   long l=KB.nextLong();
                   Long L=new Long(l);
                   System.out.println(L);

                   //float-         Float

                   System.out.println("Enter a Float Value:");
                   float f=KB.nextFloat();
                   Float F=new Float(f);
                   System.out.println(F);

                   //char-                   Character

                   System.out.println("Enter a Character:");    
                   char c=KB.next().charAt(0);
                   Character C=new Character(c);
                   System.out.println(C);

                   //double-     Double

                   System.out.println("Enter a Double:");
                   Double d=KB.nextDouble();
                   Double D=new Double(d);
                   System.out.println(D);

          }
}

OUTPUT:-
.








Write a programm in java to find second maximum of n numbers without using of array

import java.util.Scanner;
public class Example
{
public static void main(String[] args)
{
int high=0,sec_high=0;
int n;
Scanner in = new Scanner(System.in);
System.out.println("Enter the value of n:");
n= in.nextInt();
for(int i=1;i<=n;i++)
{
System.out.print("Enter the value:");
int value = in.nextInt();
if(value>high)
{
sec_high=high;
high=value;
}
else
{
if(value>sec_high)
{
sec_high=value;
}
}

}
System.out.println("Highest value:" + high);
System.out.println("Second Highest value:" + sec_high);
}
}

OUTPUT:-















Comments