Untitled
unknown
plain_text
2 years ago
1.3 kB
9
Indexable
Never
import java.util.*; import java.io.*; public class randomNumberWriter{ public static void main(String[] args){ final int randomCount = 100; try{ File randomNumber = new File("randomNums.txt"); PrintWriter randomPrinter = new PrintWriter(randomNumber); Random randomNum = new Random(); for(int num = 0; num <= randomCount; num++){ randomPrinter.println(randomNum.nextInt(300)); } randomPrinter.close(); Scanner fileReader = new Scanner(randomNumber); int max = 0; int min = 300; System.out.println("\n\n\nRandom Numbers from files are: "); while(fileReader.hasNext()){ int current = fileReader.nextInt(); if(current > max){ max = current; } if(current < min){ min = current; } System.out.println(current); } System.out.println("\n\n\nMax: "+max); System.out.println("Min: "+min); fileReader.close(); }catch(Exception e){ System.out.println("Exception executed"); } } }