정말 제가 작업하고있는 문제에 대한 도움이 필요합니다. 나는 파일을 읽은 다음 최대 및 최소 번호를 인쇄하는 데 필요한 숫자 일 수있는 .txt 파일에서 최대 및 최소 번호를 찾으려고합니다. readfile 잘 작동하고, 유일한 문제는 내가 0 대답을 얻을 수 있습니다.Readfile 최대 및 최소 번호
내 코드 :
import java.util.Scanner;
import java.io.*;
public class LargeSmall
{
public static void main(String[] args) throws IOException
{
//gets filename
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter the name of the file: ");
String filename = keyboard.nextLine();
//opens file
File file = new File(filename);
Scanner inputFile = new Scanner(file);
//place holders for varibales
int val = 0;
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
//to read all lines of file
while (inputFile.hasNext())
{
//gets min and max number
int number = inputFile.nextInt();
if (val > max)
{
max = val;
}
if (val < min)
{
min = val;
}
}
//Close file
inputFile.close();
//Print out lowest value in the list and highest
System.out.println("Min number is: " +min);
System.out.println("Max number is: " +max);
}
}
은 내가 잘못 이해하지 말고, 어떤 조언이나 도움을 주시면 감사하겠습니다! 대신
int number = inputFile.nextInt();
의
는 아 좋아, 내가 지금보고, 감사합니다 너의 도움으로! –