When I define the if statement to be if (q==1), and another one to be if (q==2), and I type 2, it still goes to the first statement, as if I typed 1.
if (u==2) {
System.out.println("Hvad har du brug for at regne ud?");
System.out.println("Tryk 1 og enter for stofmængde (n)");
System.out.println("Tryk 2 og enter for molarmasse (g/mol)(M)");
System.out.println("Tryk 3 og enter for samlet masse (m)");
int q = tastatur.nextInt();
if (q == 1); {
System.out.println("Du har valgt at regne stofmængde ud");
System.out.println("Indtast molarmasse og tryk enter");
double molarmasse = tastatur.nextDouble();
System.out.println("Indtast samlet masse og tryk enter");
double masse = tastatur.nextDouble();
double stofmængde = (masse/molarmasse);
System.out.println("Stofmængde =" +masse+ "/" +molarmasse);
System.out.println("Stofmængden =" +stofmængde);}
if (q == 2); {
System.out.println("Du har valgt at regne molarmasse ud");
System.out.println("Indtast stofmængde og tryk enter");
double stof = tastatur.nextDouble();
System.out.println("Indtast samlet masse og tryk enter");
double mass = tastatur.nextDouble();
double mm = (mass/stof);
System.out.println("Molarmasse =" +mass+ "/" +stof);
System.out.println("Molarmasse =" +mm);}}
Aucun commentaire:
Enregistrer un commentaire