Domanda di colloquio di Chetu

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

Risposte di colloquio

Anonimo

24 giu 2014

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

Anonimo

1 lug 2014

share your answer too.

Anonimo

18 lug 2018

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

Anonimo

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]

Anonimo

8 gen 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

Anonimo

14 apr 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.