我需要打印此文件中的最大和最小數字...我嘗試了一切,我似乎無法使它工作。我是初學者,請幫助閱讀文件並在java中打印最大和最小數字
public class Banck {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
System.out.println("Welcome to JEEEZBANK");
final int NUM_TO_QUIT = -99;
String userin ;
int num;
System.out.println("Enter a file ending with .txt");
Scanner scan = new Scanner(System.in);
userin = scan.nextLine();
// create file
PrintWriter file = new PrintWriter(userin);
for(int i=1; i<5; i++){
System.out.println("enter first number "+i +" or -99 to quit");
num = scan.nextInt();
if(num == NUM_TO_QUIT){
System.out.println("bye");
System.exit(0);
}
file.println(num);
}
file.close();
// read file and print smallest and biggest number
Scanner read = new Scanner(file);
while(read.hasNext()){
// add the numbers to the array
int[] numlist = {num};
// print the biggest and smallest number inside the numlist array.
}
}
}
看看[Math.min](http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#min(int,%20int))和[Math.min的.max](http://docs.oracle.com/javase/7/docs/api/java/lang/Math.html#max(INT,%20int)) – MadProgrammer 2013-03-10 04:30:59