Answer the question
In order to leave comments, you need to log in
When reading a file in java, the program compiles, but there is no result, what should I do?
When reading a file in java, the program compiles, but there is no result, what should I do?
class files{
public static void main(String args[]){
try{
BufferedReader kf = new BufferedReader(new FileReader("C:/Users/Shhhn/IdeaProjects/untitled/src/koeff.txt"));
String line = kf.readLine();
//коэфициенты квадратного уравнения
int a1 = 0;
int b1 = 0;
int c1 = 0;
while (line != null){
for (int i = 0; i != line.length(); ++i){
char kof0 = line.charAt(i);
String kof1 = String.valueOf(kof0);
//начало главного while
while(kof1!=" "){
String a = kof1;
a1 = Integer.parseInt(a);
int index_len_a = a.length()+1;
if(i==index_len_a){
while(kof1!=" "){
String b = kof1;
b1 = Integer.parseInt(b);
int index_len_b = b.length()+1;
if(i==index_len_b){
while(kof1!=" "){
String c = kof1;
c1 = Integer.parseInt(c);
}
}
}
}
}
//конец главного while
double discrim = Math.sqrt(b1*b1-4*a1*c1);
if(discrim<0){
System.out.println("solve not");
}
else{
double x1 = 0;
double x2 = 0;
x1 = (-1*b1+discrim)/(2*a1);
x2 = (-1*b1-discrim)/(2*a1);
System.out.println("x1 = "+x1+" x2 = "+x2);
}
}
}
kf.close();
}catch (IOException e){
System.out.println("Файл не найден!");
}
}
}
Answer the question
In order to leave comments, you need to log in
That's why, why, in any programming courses, no matter Java or any other language, they don't teach how to use a debugger, or at least place prints in all places?!
Gentlemen and ladies, teachers, teachers, coaches, coaches - well, first of all, teach, using the example of Hell Programming World, how to debug your creations in all possible ways.
Java is a separate conversation, in it the debugger in each IDE sticks out like a mute reproach, and the button is nearby - just stick a breakpoint.
What to do? .. as the great Krupsky said, "study, study and study again"
For your code is not a solution to a quadratic equation, it is some kind of hellish Soton.
Everything is terrible in it - from the name of the class to five (FIVE, CARL !!!) nested loops.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question