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

2013/9/22

Simple Math Program

RedFox92 RedFox92

2013/9/22

#
How could i make a simple math program using Greenfoot? Just want it to be able to add and subtract.
wabuilderman wabuilderman

2013/9/22

#
well, you could do the straght java way and go:
String int1 = new Scanner(System.in).next();
String int2 = new Scanner(System.in).next();
Int restult = ((Int) int1) + ((Int) int2)
system.out.println(result);
Note: this code would use the console, this would not necessarily work directly in greenfoot. Also, you might want to tell the user NOT to put in any letters.
Gevater_Tod4711 Gevater_Tod4711

2013/9/22

#
If you want to create this program in greenfoot you better use some GUI components like textfields and buttons (see bournes GUI Components scenario). To convert the strings from the textfields into ints you can use Integer.parseInt(String) and then simply add or subtract the int values.
danpost danpost

2013/9/22

#
What do you need help with, specifically?
You need to login to post a reply.