Results 1 to 3 of 3
- 07-19-2011, 10:10 PM #1
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
how to repeat a task again after it has been done
hey guys.
my code is simply made for rolling a 20 faced cube:
import java.util.Scanner;
import java.util.Random;
public class in {
public static void main (String args[]){
Scanner d = new Scanner (System.in);
Random a = new Random();
int b;
b = 1+a.nextInt(20);
System.out.println("press 0 to roll a 20 cube");
int c;
c = d.nextInt();
if (c == 0){
System.out.println(b);
}
}
}
I want the applet to again ask to press zero so they can roll the die again and get another random number, and not for the applet to end. help will be greatly appreciated
- 07-19-2011, 10:40 PM #2
Use a loop to repeat a section of code. For this, the while loop would work.
Put the while(...) { at the beginning
and a } at the end of the statement to be repeated.
Use Search to find plenty of code samples.
- 07-19-2011, 11:03 PM #3
Member
- Join Date
- Jul 2011
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
how to repeat my method?
By poupas in forum New To JavaReplies: 6Last Post: 11-20-2010, 06:29 PM -
turning off key-repeat
By gib65 in forum Advanced JavaReplies: 4Last Post: 08-25-2010, 02:58 PM -
Repeat a letter twice in java.
By ustar in forum New To JavaReplies: 3Last Post: 03-23-2010, 09:56 AM -
Help with a repeat
By leeavital in forum New To JavaReplies: 1Last Post: 01-01-2010, 09:42 PM -
nested <ui:repeat> - problem
By hackerofcrackers in forum JavaServer Faces (JSF)Replies: 0Last Post: 06-20-2008, 10:06 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks