943,940 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6890
  • Java RSS
Nov 17th, 2006
0

Guess Number Game (Problem)

Expand Post »
HI, i'm new in JAVA
i creating a "GUESS NUMBER GAME"..
which allow user 3 changes to guess..
i'm new to java so i need a simple coding...
i has done the part but i dun wan to combine all function in main...
this is my problem, i hope u can solve to me...
this is my coding... pls look forward it..

import javax.swing.JOptionPane;
public class game1
{
public static void main (String args[])
{
int rollOfDice, num, x;
String output,userNum;

//generate a random number betwwen 1 and 6 inclusive
rollOfDice = (int)(Math.random()*6)+1;
output = "You rolled a "+rollOfDice;

//print msg
JOptionPane.showMessageDialog(null,output,"Random Number Demo",JOptionPane.INFORMATION_MESSAGE);



do
{
userNum = JOptionPane.showInputDialog ("Please Guess the number");
num = Integer.parseInt(userNum);

if (num == rollOfDice)
{
output = "Congratulation";
JOptionPane.showMessageDialog(null,output,"Win",JOptionPane.INFORMATION_MESSAGE);
}
else
{
for (x=1;x>3;x++)
{
output = "Try again";
JOptionPane.showMessageDialog(null,output,"Lose",JOptionPane.INFORMATION_MESSAGE);
//output = "You are lose";
//JOptionPane.showMessageDialog(null,output,"Lose",JOptionPane.INFORMATION_MESSAGE);
}
}
}while(num != rollOfDice);

System.exit(0);
}
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
JesQi is offline Offline
1 posts
since Nov 2006
Nov 17th, 2006
0

Re: Guess Number Game (Problem)

Have you looked at examples of functions and how they are structured?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Jave newbie
Next Thread in Java Forum Timeline: Dasher in java





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC