sanita_sasa
Thread Starter
- Joined
- Nov 25, 2011
- Messages
- 1
hi all ;:
i have an assignment :
if the user input 5 numbers < the programme should tell him which the two largest number from them ::
example ;;
if i enter
1 , 33 , -3 , 0 , 45 ,
the programme will tell me that
largest1 = 45
largest2 = 33
how it will be
?
that code is done and working ,
but the problem that , when i give the largest2 =0
it make a problem with the result when i put negative integers
,
what should i give the 2n number as a initial value for it
i have an assignment :
if the user input 5 numbers < the programme should tell him which the two largest number from them ::
example ;;
if i enter
1 , 33 , -3 , 0 , 45 ,
the programme will tell me that
largest1 = 45
largest2 = 33
how it will be
?
PHP:
Scanner input = new Scanner( System.in );
int largest2;
int largest1 ;// largest number
int number; // user input
int counter; // number of values entered
// the second largest number
System.out.println( "Enter the number 1:" );
number = input.nextInt();
largest1=number;
counter=2;
while(counter<=5){
System.out.println( "Enter the number "+counter+":" );
number = input.nextInt();
if((number>largest1))
largest1=number;
else if
(number >= largest2 && number <= largest1)
largest2=number;
counter++ ;
}
System.out.println("largest1 :: "+largest1 );
System.out.println("largest2 ::"+largest2 );
}
}
that code is done and working ,
but the problem that , when i give the largest2 =0
it make a problem with the result when i put negative integers
,
what should i give the 2n number as a initial value for it