This site requires JavaScript, please enable it in your browser!
Greenfoot back
Everardo_Chao
Everardo_Chao wrote ...

2016/10/28

greenfoot.ask

Everardo_Chao Everardo_Chao

2016/10/28

#
I have a problem with a program on greenfoot.ask I do a sum and I must return a correct answer or incorreta but to run it just gives me the answer wrong but this good public class botones extends Actor { /** * Act - do whatever the botones wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { } public void emp() { World myw = getWorld(); int x=(myw.getWidth()); int y=(myw.getHeight()); Greenfoot.isKeyDown("space"); if (Greenfoot.isKeyDown("space")){ myw.addObject (new uno(),100, 200); myw.addObject (new dos(),400, 200); } } public void questioin() { if (Greenfoot.isKeyDown("space")){ World myw = getWorld(); int x=(myw.getWidth()); int y=(myw.getHeight()); int preg= Integer.parseInt(Greenfoot.ask("answer?")); if(preg == '3') { myw.addObject (new good(),690, 200); } else { myw.addObject (new bad (),690, 200); System.out.println(preg); } } } }
danpost danpost

2016/10/28

#
On this line:
if(preg == '3')
the single quotes around the three causes it to be treated as the character '3'. The character three has an int value of 51, which, obviously, is not 3. Remove the quotes from around the 3.
You need to login to post a reply.