Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get Highest and Lowest number from string of space separated numbers, using "for" statement
public static String HighAndLow(String numbers) {
// Code here or
String[] splitStr = numbers.split(" "); // split by " "
int lNum = Integer.parseInt(splitStr[0]); //lowest number init;
int hNum = Integer.parseInt(splitStr[0]); // highest number init;
for(int i=1; i<splitStr.length; i++){//compare
if(lNum>Integer.parseInt(splitStr[i]))
lNum = Integer.parseInt(splitStr[i]);
if(hNum<Integer.parseInt(splitStr[i]))
hNum = Integer.parseInt(splitStr[i]);
}
//"hNum lNum";
return String.valueOf(hNum)+" "+ String.valueOf(lNum);
}
@zeraf29

This comment has been minimized.

Copy link
Owner Author

zeraf29 commented Jan 9, 2019

단순히 For문을 사용하여 해결. >> Stream으로 바꾼 문구

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.