Google Search

Monday, March 2, 2015

write a Java program to find the greatest among 3 no’s using nested if Statement

ALGORITHM:

Step 1: Start

Step 2: Class gtnnestedif

Step 3: Use if and compare a,b and c

Step 4: Print the greatest no

Step 5: Stop

PROGRAM: import java.io.*; class gtnnestedif

{

public static void main(String args[])throws IOException

{BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); int a,b,c;
System.out.println("Enter the values"); a=Integer.parseInt(br.readLine()); b=Integer.parseInt(br.readLine()); c=Integer.parseInt(br.readLine()); if(a>b)

{if(a>c)

{System.out.println("A is greatest");} else
{

System.out.println("C is greatest");}} else if (b>c)
{

System.out.println("B is greatest");} else
{System.out.println("C is greatest");}}}

OUTPUT:

D:\JAVA>javac clsgtn.java D:\JAVA>java clsgtn Enter the values:

10 20 34


C is greatest

0 comments:

Post a Comment