How can i repeat it?

The following codes is a product of two number game,but if i want it repeat the game again and user can end the game.how can i do that,please give some suggestion.
import java.awt.*;
import javax.swing.*;
public class Lab10 extends JApplet
int
count = 0,
     num1,
num2,
getnum,
numsum;
     String input,
     output;
     public void init()
     num1 = 1 + (int) (Math.random() * 9);
     num2 = 1 + (int) (Math.random() * 9);
     input = JOptionPane.showInputDialog(" What is the product of " + num1 + " and " + num2 + "." );
     getnum = Integer.parseInt(input);
     public void paint( Graphics g )
     super.paint( g );
     if (getnum == num1 * num2)
     g.drawString( "Good work", 25, 25 );
     else
     g.drawString( "Try again", 25, 25 );
}     

wantToContinue = true
while (wantToContinue)
  begin while
    print "Do you want to continue : "
    read userInput
    if userInput == 'n'
       wantToContinue = false
  end whilethis is a simple pseudocode to implement your question. try to convert
this to java code.

Similar Messages

  • How can I repeat a for loop, once it's terms has been fulfilled???

    Well.. I've posted 2 different exceptions about this game today, but I managed to fix them all by myself, but now I'm facing another problem, which is NOT an error, but just a regular question.. HOW CAN I REPEAT A FOR LOOP ONCE IT HAS FULFILLED IT'S TERMS OF RUNNING?!
    I've been trying many different things, AND, the 'continue' statement too, and I honestly think that what it takes IS a continue statement, BUT I don't know how to use it so that it does what I want it too.. -.-'
    Anyway.. Enought chit-chat. I have a nice functional game running that maximum allows 3 apples in the air in the same time.. But now my question is: How can I make it create 3 more appels once the 3 first onces has either been catched or fallen out the screen..?
    Here's my COMPLETE sourcecode, so if you know just a little bit of Java you should be able to figure it out, and hopefully you'll be able to tell me what to do now, to make it repeat my for loop:
    Main.java:
    import java.applet.*;
    import java.awt.*;
    @SuppressWarnings("serial")
    public class Main extends Applet implements Runnable
         private Image buffering_image;
         private Graphics buffering_graphics;
         private int max_apples = 3;
         private int score = 0;
         private GameObject player;
         private GameObject[] apple = new GameObject[max_apples];
         private boolean move_left = false;
         private boolean move_right = false;
        public void init()
            load_content();
            setBackground(Color.BLACK);
         public void run()
              while(true)
                   if(move_left)
                        player.player_x -= player.movement_speed;
                   else if(move_right)
                        player.player_x += player.movement_speed;
                   for(int i = 0; i < max_apples; i++)
                       apple.apple_y += apple[i].falling_speed;
                   repaint();
                   prevent();
                   collision();
              try
              Thread.sleep(20);
              catch(InterruptedException ie)
              System.out.println(ie);
         private void prevent()
              if(player.player_x <= 0)
              player.player_x = 0;     
              else if(player.player_x >= 925)
              player.player_x = 925;     
         private void load_content()
         MediaTracker media = new MediaTracker(this);
         player = new GameObject(getImage(getCodeBase(), "Sprites/player.gif"));
         media.addImage(player.sprite, 0);
         for(int i = 0; i < max_apples; i++)
         apple[i] = new GameObject(getImage(getCodeBase(), "Sprites/apple.jpg"));
         try
         media.waitForAll();     
         catch(Exception e)
              System.out.println(e);
         public boolean collision()
              for(int i = 0; i < max_apples; i++)
              Rectangle apple_rect = new Rectangle(apple[i].apple_x, apple[i].apple_y,
    apple[i].sprite.getWidth(this),
    apple[i].sprite.getHeight(this));
              Rectangle player_rect = new Rectangle(player.player_x, player.player_y,
    player.sprite.getWidth(this),
    player.sprite.getHeight(this));
              if(apple_rect.intersects(player_rect))
                   if(apple[i].alive)
                   score++;
                   apple[i].alive = false;
                   if(!apple[i].alive)
                   apple[i].alive = false;     
         return true;
    public void update(Graphics g)
    if(buffering_image == null)
    buffering_image = createImage(getSize().width, getSize().height);
    buffering_graphics = buffering_image.getGraphics();
    buffering_graphics.setColor(getBackground());
    buffering_graphics.fillRect(0, 0, getSize().width, getSize().height);
    buffering_graphics.setColor(getForeground());
    paint(buffering_graphics);
    g.drawImage(buffering_image, 0, 0, this);
    public boolean keyDown(Event e, int i)
         i = e.key;
    if(i == 1006)
    move_left = true;
    else if(i == 1007)
         move_right = true;
              return true;     
    public boolean keyUp(Event e, int i)
         i = e.key;
    if(i == 1006)
    move_left = false;
    else if(i == 1007)
         move_right = false;
    return true;
    public void paint(Graphics g)
    g.drawImage(player.sprite, player.player_x, player.player_y, this);
    for(int i = 0; i < max_apples; i++)
         if(apple[i].alive)
              g.drawImage(apple[i].sprite, apple[i].apple_x, apple[i].apple_y, this);
    g.setColor(Color.RED);
    g.drawString("Score: " + score, 425, 100);
    public void start()
    Thread thread = new Thread(this);
    thread.start();
    @SuppressWarnings("deprecation")
         public void stop()
         Thread thread = new Thread(this);
    thread.stop();
    GameObject.java:import java.awt.*;
    import java.util.*;
    public class GameObject
    public Image sprite;
    public Random random = new Random();
    public int player_x;
    public int player_y;
    public int movement_speed = 15;
    public int falling_speed;
    public int apple_x;
    public int apple_y;
    public boolean alive;
    public GameObject(Image loaded_image)
         player_x = 425;
         player_y = 725;
         sprite = loaded_image;
         falling_speed = random.nextInt(10) + 1;
         apple_x = random.nextInt(920) + 1;
         apple_y = random.nextInt(100) + 1;
         alive = true;
    And now all I need is you to answer my question! =)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    package forums;
    import java.util.Random;
    import javax.swing.Timer;
    import javax.imageio.ImageIO;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class VimsiesRetardedAppleGamePanel extends JPanel implements KeyListener
      private static final long serialVersionUID = 1L;
      private static final int WIDTH = 800;
      private static final int HEIGHT = 600;
      private static final int MAX_APPLES = 3;
      private static final Random RANDOM = new Random();
      private int score = 0;
      private Player player;
      private Apple[] apples = new Apple[MAX_APPLES];
      private boolean moveLeft = false;
      private boolean moveRight = false;
      abstract class Sprite
        public final Image image;
        public int x;
        public int y;
        public boolean isAlive = true;
        public Sprite(String imageFilename, int x, int y) {
          try {
            this.image = ImageIO.read(new File(imageFilename));
          } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("Bailing out: Can't load images!");
          this.x = x;
          this.y = y;
          this.isAlive = true;
        public Rectangle getRectangle() {
          return new Rectangle(x, y, image.getWidth(null), image.getHeight(null));
      class Player extends Sprite
        public static final int SPEED = 15;
        public Player() {
          super("C:/Java/home/src/images/player.jpg", WIDTH/2, 0);
          y = HEIGHT-image.getHeight(null)-30;
      class Apple extends Sprite
        public int fallingSpeed;
        public Apple() {
          super("C:/Java/home/src/images/apple.jpg", 0, 0);
          reset();
        public void reset() {
          this.x = RANDOM.nextInt(WIDTH-image.getWidth(null));
          this.y = RANDOM.nextInt(300);
          this.fallingSpeed = RANDOM.nextInt(8) + 3;
          this.isAlive = true;
      private final Timer timer = new Timer(200,
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            repaint();
      public VimsiesRetardedAppleGamePanel() {
        this.player = new Player();
        for(int i=0; i<MAX_APPLES; i++) {
          apples[i] = new Apple();
        setBackground(Color.BLACK);
        setFocusable(true); // required to generate key listener events.
        addKeyListener(this);
        timer.setInitialDelay(1000);
        timer.start();
      public void keyPressed(KeyEvent e)  {
        if (e.getKeyCode() == e.VK_LEFT) {
          moveLeft = true;
          moveRight = false;
        } else if (e.getKeyCode() == e.VK_RIGHT) {
          moveRight = true;
          moveLeft = false;
      public void keyReleased(KeyEvent e) {
        moveRight = false;
        moveLeft = false;
      public void keyTyped(KeyEvent e) {
        // do nothing
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        //System.err.println("DEBUG: moveLeft="+moveLeft+", moveRight="+moveRight);
        if ( moveLeft ) {
          player.x -= player.SPEED;
          if (player.x < 0) {
            player.x = 0;
        } else if ( moveRight ) {
          player.x += player.SPEED;
          if (player.x > getWidth()) {
            player.x = getWidth();
        //System.err.println("DEBUG: player.x="+player.x);
        Rectangle playerRect = player.getRectangle();
        for ( Apple apple : apples ) {
          apple.y += apple.fallingSpeed;
          Rectangle appleRect = apple.getRectangle();
          if ( appleRect.intersects(playerRect) ) {
            if ( apple.isAlive ) {
              score++;
              apple.isAlive = false;
        g.drawImage(player.image, player.x, player.y, this);
        for( Apple apple : apples ) {
          if ( apple.isAlive ) {
            g.drawImage(apple.image, apple.x, apple.y, this);
        g.setColor(Color.RED);
        g.drawString("Score: " + score, WIDTH/2-30, 10);
      private static void createAndShowGUI() {
        JFrame frame = new JFrame("Vimsies Retarded Apple Game");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().add(new VimsiesRetardedAppleGamePanel());
        frame.pack();
        frame.setSize(WIDTH, HEIGHT);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      public static void main(String[] args) {
        SwingUtilities.invokeLater(
          new Runnable() {
            public void run() {
              createAndShowGUI();
    }Hey Vimsie, try resetting a dead apple and see what happens.

  • How can we repeat specific page number of pdf file by using FDF Toolkit for Windows?

    how can we repeat specific page number of pdf file by using FDF Toolkit for Windows?

    let's say a registration form, there is only 1 full address provided in my registration pdf, but applicant could have more than 1 address, so i have to make it more flexible to extend the address page no matter how many addresses that applicant provided, i have use adobe acrobat pro to edit the form properties. but dont know how to extend/duplicate a page in felxible times.
    Please advise~ tks so much!!! George

  • How can I repeat a video on my ipad?

    How can I repeat a video on my ipad?  There is no option to repeat videos.

    There is a special subforum for the iOS version of Reader: Adobe Reader for iOS

  • How can I repeat my flash animation (my frames)?

    Hi Flash forum members
    Can you help me somebody: How can I repeat my flash animation (my frames) many times?
    I will be looking forward to hearing from you,
    Sultan

    It depends on what you mean and how your design is done.
    You can copy and paste frames as many times along a timeline as you, though creating a movieclip of one set and placing that to extend the full length of the timeline would produce the same result.
    If the problem is that your animation stops when it is done, you need to be sure to not have any code in place that will stop it.

  • How can I repeat the same program automatically with a time-plan?

    Hello Everyone,
    I have a question here.
    I want to start the same program more time, but I would like to define the number of repetitions and time delay between each repetition with a dialog windows.How can I do that? 
    e.g. I want to repeated the same program for 4 times, first time this program will be started by press "Start", second time it will be started in 10 seconds after the first start, the third time it will be started in 16 seconds after the first start and last time ist in 30 seconds after the first start.
    With which node can I do that?
    Regart,
    Johnny

    Hi,
    try something like this.
    Mike
    Attachments:
    Unbenannt 5_LV80.vi ‏12 KB

  • How can I repeat the order?

    I have a form with some options which the user must choose. That done, he must repeat the process "as a kind of basket button", how can I do this?

    Formscentral doesn't support dynamically repeating fields, therefore you need to create the repeated field as many times as you think the users will need during the form design process. You can then set up skip logic to allow them to skip all of the repeated fields they don't need. If dynamically repeated fields are a requirement for your application you would be better off looking into Adobe Livecycle for  a solution.
    Andrew

  • Please, how can i repeat?

    Dear Apple users,
    i have an important and urgent question about arrange audio with video (Final Cut Pro) in Soundtrack.
    1) I have created a sequence in Final Cut HD and i have sent sequence >> to Soundtrack Pro, ok? It's correct this workflow?
    2) In SoundTrack Pro (like Avid) i wan't to repeate a little bit of an audio track (like a drum in end of a song) smoothly (expanding track, repeating a little part of this audio with no simple and orrible cut and paste?
    3) Can i return back to Final Cut with a project arrange in Soundtrack Pro?
    How can i do or what do you suggest to me?

    Does that happen when you use the Back button? If so, don't use the Back button, right-click or click-hold that Back button and use the Back / Forward history menu that appears to load the previous page from that menu. That should avoid the appearance of that security warning message, which can't be turned off. If that is happening on web pages that don't involve financial transactions, that website really should be fixed so that security message doesn't appear.

  • How can I repeat a handwriting effect?

    Hi there,
    So I'm new to flash and I've switched over because my powerpoint animations were becoming too complex and the video output I was trying to upload to YouTube just didn't look as good as I'd hoped.
    I really liked the ability to quickly "wipe" in an object from the left so that it looked like I was drawing it. I'm basically making a presentation that has lots of arrows and lots of things getting crossed out as I build and solve some math problems. I'm wondering if there's an easier way than stepping through 4 or 5 key frames and erasing a chunk of the line and then reversing the whole sequence? This method would take forever for what I'm wanting to do, so I'm hoping there's a quick way for me to accomplish this?
    Here's a video of what I'm talking about:

    Hey,
    Since the new HTML5 Canvas tools do not support masks you may need to get creative with different gradient PNG files and layering. For example, you put you text on a layer, then on the layer above it you position a box with a gradient that starts at 0% opacity and moves to match the background color, then animate a move from left to right sliding the gradient off the text to "reveal" it. This works well enough on a solid background but becomes un-useable when you use it on an image or gradient background.
    If you are working in AS3 versus the HTML5 canvas you can apply a mask to the text layer that reveals on a timeline, check out the tutorials on masking.
    If you want some serious text animation tools that will really knock your socks off check out AfterEffects. The text tools there are really powerful and can be outputted as small video files that you can then add to the AS3 version of the timeline. I am just getting into the HTML5 canvas version in Flash and thus far I have not found a way to use video files within the animations. I have that question in the Forum too.
    If you want the project to be viewable on the iOS operating system (iPad/iPhone) then you are limited to using the new HTML5 canvas and therefore the masking and video limitations are in effect. I guess since this tool is so new they were not able to get all the functionality into the new platform.
    If all you are looking to do is create Slideshows that you play from your laptop and/or videos that are posted on YouTube then the AS3 tools will make easy work of the text effects you are looking to accomplish, just learn as much as you can about masking and using gradient PNG files. If you have the Creative Cloud and are a little adventurous, check out AfterEffects and the text tools there, they will help you create any text effect you have ever dreamt of.
    2 more things you may be interested in:
    First, in AfterEffects you have the ability to program a timed reveal of the strokes on handwritten fonts. That means that if you set it up correctly you can automatically set up a handwriting reveal that looks like actual handwriting with pen strokes, again take a look at the tutorials, The function is called animating a stroke and I have seen several in the Adobe tutorial videos over the years.
    Secondly, one of the hurdles in using Flash as a slideshow generation tool is how to get the remote in your hand to animate the frames in the show. Unless you are standing at the keyboard hitting the buttons you program in to advance to the next slide you will want a remote to handle this functionality. The bluetooth remote for the Mac and the IR remote for PCs will not do this automatically, you will need to program in that functionality and to do that you need the computer to recognize the remote's button presses as a certain key press so you can trigger the function on that key press. For the Mac I have had success with the Better Touch Tool ap. It allows for assigning the button press on the Mac Remote to do specialized keypresses that I then insert into the AS3 of my slideshow to trigger the next frame or previous frame. I was even able to program the up button to go to the beginning of the presentation and the down button to go to the end.
    I hope some of this helps.

  • How can I repeat a command?

    I am using Ai3.
    I am doing a lot of "path simplify" and every time I have to go to "object" then "path" then "path simplify".
    I have been searching if there is like in autocad a key to press to do "repeat las action" but I only found 2 things that I dont really understand:
    - Ctrl + D (must be for st else)
    - somethnig called "actions", if I understand correctly it is to create a group of commands, this could be interesting but it should be next to the "pathfinder" screen but there I have nothing...
    strange,
    somebody to help?
    Thanks, Danke

    Make a feature request.
    Illustrator and in general many Adobe products are lacking considerably with repeated tasks. The number of hotkeys available is limited to using Function keys and a lot of them are already assigned by default to frequently used tasks. Also, often users need to repeat a task frequently in one or a few sessions but not every day on a regular bases which doesn't justify creating an action and occupying a hotkey that is easy to forget if not used daily. Nowadays production programs are brimming with features and there are a lot of excellent solutions already invented and used by may programs but unfortunately Illustrator is not one of them. Here are some examples of excellent solutions:
    a hotkey for the last menu command selected
    a hotkey for the previous tool selected (for example while using the Sheer Tool on existing objects, you want to draw a box and quickly go back to the Sheer Tool)
    list of recently used menu commands panel
    tearoff menus similar to the existing tearoff toolbars (imagine it was possible when you go to Object > Paths be able to tear off the Paths submenu so it remains like a panel and you can click on any of the commands of this submenu without digging through the menus again and again)

  • How can I repeat a playlist on iTunes 12.0.1.26?

    Hello,
    I have struggles with being able to repeat a playlist since the iTunes update. I haven't been able to find the button that allows you to repeat a playlist. Not sure if it's in the open and I'm just stupid or if they actually changed it. Can someone let me know? Thanks so much and have a great day!

    You can access the repeat options if you right-click on the shuffle icon, or if menus are enabled you can use
    Controls > Repeat > Off | All | One.
    Once the control is visible you can click it to switch between states as before. If the control is turned to off it disappears on the next track change. In contrast the shuffle control remains visible whenever it is appropriate. Hopefully the next release will fix this.
    tt2

  • C5 - How can you repeat a To-Do in the calendar ??

    Hi all,
    I have several things I have to repeat each week and I used to be able to put these events in the calendar of my old 6300 and repeat them as a reminder. It seems I cannot in the C5.
    Can anyone help ??
    Thanks
    Bullgong 

    Looks like a to-do cannot be repeated. But you can make it a meeting appointment that
    repeats.

  • How can I repeat an event in Calendar on a specific day.

    I want to set a repeat event on a specific day each month, like the Last Tuesday.  Also I'd like to set a quarterly repeat event.

    Using the native calander, the only options you have are those that pop up when you hit 'repeat'.  So if you are looking for a specific date each month, you are fine, but looking for the 4th tuesday, you are not fine.  You might search the app store for non apple alternatives.

  • Can I repeat and record the same music tracks in Itunes

    How can I repeat and record the same music tracks in Itunes

    I would advise against this.
    You can redownload some itunes purchases from itunes, but there is no guarantee that it will be there in the future.

  • How can I set an event to repeat on a week day rather than a numerical day of each month?

    How can I set an event to repeat on a week day rather than a numerical day of each month? I see an option at the bottom of the repeat window .... but I cannot use it. Actually, when I try it freezes up my Calendar.
    Lorrene Baum Davis

    These scrrenshots are from Snow Leopard - I would think that Lion wouldn't be too much different.

Maybe you are looking for

  • Inconsistency between tbtco and tbtcs

    Hello guys, we have a big problem after our HWU upgrade. We have copied the content of tbtco into a new table tbtco_copy before the upgrade to save all the job entries. After this we have deleted the contant of tbtco. So we had no scheduled jobs for

  • Brother MFC 9700 and Canon i960 will not print under Snow Leopard

    After checking the compatibility documentation which indicated that the above printers had drivers which would work w/Snow Leopard, I upgraded to10.6. Now neither printer will work i.e. the document goes into the print queue but won't print. I've unp

  • Exporting to a Tab delimited file.

    Post Author: John CA Forum: Exporting I'm having a problem with my first line (only in the first column) being 1 space over to the left.  This causes the whole file to not be read by my Access database (except the first line).  My file is coming from

  • Gateway eror

    Hey all ! I am getting this weird error in one of my Portal Gateways, does anyone know what could be happening?? 10/4/04 8:20:02 PM CDT: Thread[Thread-142,5,main] ERROR: ServerCertApprovalCallback: reason -8156 10/4/04 8:20:02 PM CDT: Thread[Thread-1

  • Where to download 2.3.4's optional plugins?

    Hi, My company's finance department have purchased the licences for standard edition and plugins for caching. Where do I download the 2.3.4's optional plugins? Thanks in advance.