Is it possible to write less for example by writing the conditions into one if- instruction or something like that.My point is to cut the source code and find a better way to sum the informations in the if instruction up.
import java.util.*;
public class LinGlj4u {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Bitte geben sie den Wert für a ein : ");
double a = input.nextDouble();
System.out.print("Bitte geben sie den Wert für b ein : ");
double b = input.nextDouble();
double rechnung;
if (a + b > 0) {
rechnung = -b / a;
System.out.println(rechnung);
} else if (a + b < 0) {
rechnung = +b / a;
System.out.println(rechnung);
} else if (a + b == 0 || a - b == 0) {
System.out.println("x = 0");
}
}
}
Aucun commentaire:
Enregistrer un commentaire