Pregunta de entrevista de Chetu

Program to find out middle number among three variables using only if else in java .

Respuestas de entrevistas

Anónimo

24 jun 2014

I done that program correct but HR said it is incorrect.

Anónimo

1 jul 2014

share your answer too.

Anónimo

18 jul 2018

there is the simple way to answer tjis.. we can just check the alsphabed in ascii code. and then compare.

Anónimo

28 nov 2018

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in= new Scanner(System.in); int [] arr=new int[3]; for (int i=0;i<3;i++) { arr[i]=in.nextInt(); } int mid=MidCalc(arr); System.out.println(mid); } public static int MidCalc(int [] arr) { if (arr[0]

Anónimo

8 ene 2015

var A =10, B=5, C=15, mid=0, flag=0; if(A>B && B>C) mid = B; else if ( A>C && C>B) mid = C; else if ( B>A && A>C) mid = A; else if ( B>C && C>A) mid = C; else if ( C>A && A>B) mid = A; else if ( C>B && B>AB) mid = B; else print("two or more numbers have same value"); flag=1; if(flag=0) { print("Middle number is "+mid); } please ignore any syntax discrepancy. Kindly see logic only.

1

Anónimo

14 abr 2015

var A =10, B=5, C=15, mid=0, flag=0; if(A>B && B>C || C>B && B>AB) mid = B; else if ( A>C && C>B || B>C && C>A) mid = C; else if ( B>A && A>C || C>A && A>B) mid = A; else print("two or more numbers have same value"); flag=1; if(flag=0) { print("Middle number is "+mid); } There is single problem that you increase the execution time with using unneccessary else if while you can use OR operator also.Your logic is right but the execution of its wrong.