java - code runs but no output is generated -
trying improve skills @ coding. after running bellow code, receive build message. appreciated in advance.
package javacourse; public class monopoly { public int diceroll(int sides){ double randomnum = math.random() * 6; randomnum = randomnum + 1; return (int) randomnum; } public int monopolyroll(){ int dice1 = diceroll(6); int dice2 = diceroll(6); int tot = dice1 + dice2; if(dice1 == dice2){ int dice3 = diceroll(6); int dice4 = diceroll(6); tot = tot + dice3 + dice4; } return tot; } public static void main(string[] args) { } }
the code doesn't show because didn't anything, can in case execute print example using system.out.println
function, can see in example bellow:
also learning how code, important using indentation, code more easy read.
package javacourse; public class monopoly { public int diceroll(int sides) { double randomnum = math.random()*6; randomnum =randomnum + 1; return (int)randomnum; } public int monopolyroll() { int dice1 = diceroll(6); int dice2 = diceroll(6); int tot = dice1 + dice2; if (dice1 == dice2) { int dice3 = diceroll(6); int dice4 = diceroll(6); tot = tot + dice3 + dice4; } return tot; } public static void main(string[] args) { monopoly monopoly = new monopoly(); system.out.println("monopolyroll"); system.out.println(monopoly.monopolyroll()); } }
don't thinks it's better read?
another thing, functions public only, need instantiate class in order call them, because of must execute new monopoly();
create object of class.
Comments
Post a Comment