Created
October 12, 2013 18:42
-
-
Save imduffy15/6953420 to your computer and use it in GitHub Desktop.
Find largest number in a text file with java
This file contains 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
import java.io.*; | |
import java.util.*; | |
class LargestFromTextFile { | |
public static void main(String[] args) { | |
try { | |
Scanner file = new Scanner(new File("numbers.txt")); | |
int largest = file.nextInt(); | |
while(file.hasNextInt()) { | |
int number = file.nextInt(); | |
if(number > largest) { | |
largest = number; | |
} | |
System.out.println(number); | |
} | |
file.close(); | |
System.out.println("The biggest number in the file is: " + largest); | |
} catch(IOException e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
} |
This file contains 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
1 | |
2 | |
3 | |
4 | |
5 | |
10 | |
6 | |
7 | |
8 | |
9 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you