Created
May 4, 2013 12:52
-
-
Save anonymous/5517423 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class fourtyseven2 | |
{ | |
public static void main (String[] args) | |
{ | |
int[] data = {1000,1000,5,1000,4,12,-3,999,0,1000}; | |
//check whether there are max and secondmax | |
boolean allthesame=true; | |
for(int value:data) | |
{ | |
allthesame=(data[0]==value)? true:false; | |
if (allthesame==false) | |
{ | |
break; | |
} | |
} | |
//declare & init | |
int max=data[0], secondmax=data[0]; | |
if(allthesame==false) | |
{ | |
//comp max | |
for(int value:data) | |
{ | |
if(value>max) | |
{ | |
max=value; | |
} | |
} | |
//change secondmax to value lower than max | |
for(int value:data) | |
{ | |
if(value<max) | |
{ | |
secondmax=value; | |
break; | |
} | |
} | |
//calc secondmax | |
for(int value:data) | |
{ | |
if(value<max && value>secondmax) | |
{ | |
secondmax=value; | |
} | |
} | |
} | |
//write out the two largest | |
System.out.println("max: "+max); | |
if(allthesame==false) | |
{ | |
System.out.println("secondmax: "+secondmax); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment