파일에서 함수를 계산할 때 사용해야하는 정수 값을 읽습니다. multiple
.문자열 값을 파일에서 정수로 변환
그러나 정수로 변환 한 후 정수 변수는 더 이상 계산할 수 없습니다.
도움이 필요하십니까?
import java.io.*;
public class Functions {
int values, mul7, mul11, mul13;
public static void main (String []args) {
Functions go = new Functions();
go.multiple();
// will call functions here
}
public void multiple() {
int a = 7;
int b = 11;
int c = 13;
try {
File inputFile = new File ("JavaInputData.txt");
FileReader fileReader = new FileReader (inputFile);
BufferedReader reader = new BufferedReader (fileReader);
String line = null;
while ((line = reader.readLine()) !=null)
{
values = Integer.parseInt(line);
System.out.println(values);
}
mul7 = values % a;
mul11 = values %b;
mul13 = values %c;
System.out.println(mul7);
reader.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
'while' 루프에서 전체 파일을 읽으므로'values'의 마지막 값만 실제로 사용됩니다. 어쨌든 'values'는 어디에 정의되어 있습니까? –
@ PM77-1 필드입니다. 클래스 선언 상단에 정의됩니다. –