mardi 24 février 2015

Why does my program stop working before an if statement? [duplicate]


This question already has an answer here:




i'm working on a random program for homothety. when i run it, my program stops before an if-statement; first i tought it was a bug with the "nextint()" so i added lines, but i saw that there is an problem with my if-statement.


could anybody help me with this bug? PS: sorry, i'm from belgium so the Strings are typed in Dutch, and sorry for my rediculas spelling of words in English.



//vars
int x;
int y;
int z;
String categ;
Scanner i = new Scanner(System.in);
int k;
int xres;
int yres;
int zres;
//input
System.out.println("geef de vorm van het originele voorwerp als volgt op:");
System.out.println("A = driehoek");
System.out.println("B = vierkant");
categ = i.nextLine();

if(categ == "A" || categ == "a"){

System.out.println("geef zijde x in: ");
x = i.nextInt();
System.out.println("geef zijde y in: ");
y = i.nextInt();
System.out.println("geef zijde z in: ");
z = i.nextInt();
System.out.println("geef de vergrotingsfactor in: ");
k = i.nextInt();

xres = x * k;
yres = y * k;
zres = z * k;

System.out.println("\nna homothetie is\nx "
+ xres +" cm,\ny: "
+ yres + " cm\nen z: "
+ zres + " cm.");

}else{
if(categ == "B" || categ == "b"){

System.out.println("geef zijde x in: ");
x = i.nextInt();
System.out.println("geef zijde y in: ");
y = i.nextInt();
System.out.println("geef de vergrotingsfactor in: ");
k = i.nextInt();

xres = x * k;
yres = y * k;

System.out.println("\nna homothetie is\nx "
+ xres +" cm,\nen y "
+ yres + " cm");`


...


Aucun commentaire:

Enregistrer un commentaire