Results 1 to 3 of 3
  1. #1
    eyal3400 is offline Member
    Join Date
    Jul 2011
    Rep Power

    Lightbulb 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 (;
    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){

    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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    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.

  3. #3
    eyal3400 is offline Member
    Join Date
    Jul 2011
    Rep Power

Similar Threads

  1. how to repeat my method?
    By poupas in forum New To Java
    Replies: 6
    Last Post: 11-20-2010, 06:29 PM
  2. turning off key-repeat
    By gib65 in forum Advanced Java
    Replies: 4
    Last Post: 08-25-2010, 02:58 PM
  3. Repeat a letter twice in java.
    By ustar in forum New To Java
    Replies: 3
    Last Post: 03-23-2010, 09:56 AM
  4. Help with a repeat
    By leeavital in forum New To Java
    Replies: 1
    Last Post: 01-01-2010, 09:42 PM
  5. nested <ui:repeat> - problem
    By hackerofcrackers in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 06-20-2008, 10:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts