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

2014/11/4

Changing Random Int to String

xxPythonslayeRxx xxPythonslayeRxx

2014/11/4

#
Need some help with this is possible I wont to change thedice to a string but Integer.parseInt doesnt work Thanks PyhtonSlayer import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) import java.awt.Color; import javax.swing.*; // Shows number import java.io.*; /** /** * Write a description of class dice here. * * @author (your name) * @version (a version number or a date) */ public class dice extends Actor { public dice() { GreenfootImage textImage = new GreenfootImage ( "roll dice" ,30, Color.BLACK, Color.WHITE); setImage(textImage); // Shows text on world. } public void act() { if(Greenfoot.mouseClicked(this)) { int thedice = 0; thedice = Greenfoot.getRandomNumber (6); GreenfootImage textImage = new GreenfootImage ( thedice ,30, Color.BLACK, Color.WHITE); setImage(textImage); } } }
danpost danpost

2014/11/4

#
Did you try the 'toString' method?
xxPythonslayeRxx xxPythonslayeRxx

2014/11/4

#
No how should i do that?
danpost danpost

2014/11/4

#
There are several ways to convert an int value to a String representation of that value
1
2
3
String valueAsString = ""+(/* int value */); // forces conversion of int to String
String valueAsString = new Integer(/* int value */).toString(); // uses Integer instance method to convert
String valueAsString = String.toString(/* int value */); // uses String class method to convert
There may be other ways as well.
xxPythonslayeRxx xxPythonslayeRxx

2014/11/6

#
Thankyou very much dan. I found another way but this none the less helped me through me journey TO BE A MASTER CODER!
xxX_Muffin.man_Xxx xxX_Muffin.man_Xxx

2014/11/6

#
happy halloween
You need to login to post a reply.