Computer Science, asked by singhbob2018, 1 year ago

Write a program in java to input 3 numbers and find the second largest number.

Answers

Answered by jyotisikhadash2
10

//to find the second largest no

import java.io.*;

class seclar

{

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

{

BufferedReader br= new BufferedReader (new InputStreamReader(System.in));

int a,b,c,d=0,min=0,max=0,e=0;

System.out.prinln("enter 3 no");

a=Integer.parseInt(br.readLine());

b=Integer.parseInt(br.readLine());

c=Integer.parseInt(br.readLine());

// find sum of 3 no

d=a+b+c;

max=a;// let a be the largest

min=a; let a be the smallest

if(b>max)

max= b;

else if (c>max)

max=c;

else

max=a;// finding the largest of

3 numbers

if(b<min)

min= b;

else if(c<min)

min = c;

else

min=a;//finding the smallest of

3 no

e= d-(max+min);// finding the

second largest no

}

}

Hope it helps !!!

mark me as the brainliest⭐⭐⭐⭐⭐


singhbob2018: Can you please make this program using if else statement
jyotisikhadash2: Is it fine now???
jyotisikhadash2: Its in If- else
singhbob2018: yes
Answered by shirisha1981
1

Answer:import java.io.*;

class seclar

{

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

{

BufferedReader br= new BufferedReader (new InputStreamReader(System.in));

int a,b,c,d=0,min=0,max=0,e=0;

System.out.prinln("enter 3 no");

a=Integer.parseInt(br.readLine());

b=Integer.parseInt(br.readLine());

c=Integer.parseInt(br.readLine());

// find sum of 3 no

d=a+b+c;

max=a;// let a be the largest

min=a; let a be the smallest

if(b>max)

max= b;

else if (c>max)

max=c;

else

max=a;// finding the largest of

3 numbers

if(b<min)

min= b;

else if(c<min)

min = c;

else

min=a;//finding the smallest of

3 no

e= d-(max+min);// finding the

second largest no

}

}

Read more on Brainly.in - https://brainly.in/question/9771808#readmore

Similar questions