Pergunta de entrevista da empresa Chetu

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

Respostas da entrevista

Sigiloso

24 de jun. de 2014

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

Sigiloso

1 de jul. de 2014

share your answer too.

Sigiloso

18 de jul. de 2018

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

Sigiloso

28 de nov. de 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]

Sigiloso

8 de jan. de 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

Sigiloso

14 de abr. de 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.