Results 1 to 10 of 10
  1. #1
    Krock999 is offline Member
    Join Date
    Jul 2013
    Posts
    10
    Rep Power
    0

    Default How Do You Make Your Code Rewind to Redo Something?

    This is my code:
    [INDENT]
    package Kyle;
    import java.util.Scanner;

    public class kyle {
    public static void main(String[] args) {
    Scanner Question = new Scanner(System.in);
    String X = Question.nextLine();
    if(X == X.toUpperCase() && X == X.toLowerCase()) {
    System.out.println("*laughs* Heh, I am glad that I broke your 'non-quitting' spirit.");
    }
    else if (X == X.toUpperCase()) {
    System.out.println("If you keep talking I will kill you!");
    System.out.println("Heh, do you think screaming '" + (X) + "' will make me stop being ahead of your bodily dissapointments?");

    }
    else if(X != X.toUpperCase()) {
    System.out.println("If you keep talking I will kill you!");
    System.out.println("Heh, do you think saying '" + (X) + "' will make me stop being ahead of your bodily dissapointments?");
    }

    }

    }
    [/LEFT]

    How do I make this redo itself?

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: How Do You Make Your Code Rewind to Redo Something?

    First, please wrap your code in [CODE][/CODE] tags not quote tags. And I suggest you read the forum rules under the FAQ.

    When you say rewind or redo, I presume you want to repeat the code to keep on asking for the values again. This can be done with a loop such as a for loop or while loop.

    Check out the tutorials at the link in my signature. It covers everything from the basics to the advanced.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    AidoP is offline Learner
    Join Date
    Nov 2012
    Location
    Margaret River
    Posts
    7
    Rep Power
    0

    Default Re: How Do You Make Your Code Rewind to Redo Something?

    Either put it in a new method and call it whenever you need it
    Java Code:
     public int/void/whatever *name*(*paramaters*){
    *Code here*
    }
    or put it in a while loop
    Java Code:
     while(*value/true(for going over and over)*){
    *code here*
    }

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: How Do You Make Your Code Rewind to Redo Something?

    or go crazy: combine the both of them.

    Control Flow Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

    It makes me sad when people ask questions that clearly show they do not have a book to learn from :( Why make your life so difficult?

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: How Do You Make Your Code Rewind to Redo Something?

    Quote Originally Posted by gimbal2 View Post
    or go crazy: combine the both of them.

    Control Flow Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

    It makes me sad when people ask questions that clearly show they do not have a book to learn from :( Why make your life so difficult?
    It's especially funny when people make up their own syntax and expect it to work, because 'it works in Basic' and even 'if Java doesn't understand that, Java is silly/broken etc.' ;-) I can't blame the bartender in an English spoken country if he doesn't understand my order 'natake bombe jabombe kubua mbili!' while Swahili speaking folks would (probably?) understand me ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: How Do You Make Your Code Rewind to Redo Something?

    Quote Originally Posted by JosAH View Post
    I can't blame the bartender in an English spoken country if he doesn't understand my order 'natake bombe jabombe kubua mbili!' while Swahili speaking folks would (probably?) understand me ...
    That's an oddly specific example. You've been waiting for a chance to use it, haven't you? ;)

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default Re: How Do You Make Your Code Rewind to Redo Something?

    Quote Originally Posted by JosAH View Post
    ... my order 'natake bombe jabombe kubua mbili!'
    Blonde, brunette or redhead, Sir?
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: How Do You Make Your Code Rewind to Redo Something?

    Quote Originally Posted by gimbal2 View Post
    That's an oddly specific example. You've been waiting for a chance to use it, haven't you? ;)
    Nope, it's an old example of mine and I use it all the time (when applicable) ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: How Do You Make Your Code Rewind to Redo Something?

    Quote Originally Posted by DarrylBurke View Post
    Blonde, brunette or redhead, Sir?
    What did I say? I thought I only ordered two large beers ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    Krock999 is offline Member
    Join Date
    Jul 2013
    Posts
    10
    Rep Power
    0

    Default Re: How Do You Make Your Code Rewind to Redo Something?

    You answered my question. Thank you.

Similar Threads

  1. problem with editorkit-undo/redo
    By jogendar in forum Advanced Java
    Replies: 6
    Last Post: 01-28-2010, 02:28 PM
  2. redo and undo feature for jtable
    By anilkumar_vist in forum AWT / Swing
    Replies: 1
    Last Post: 01-05-2010, 09:45 AM
  3. SWT Undo Redo
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 04:43 PM
  4. Undo/Redo JTextArea
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-27-2008, 07:52 PM
  5. rewind like a video tape
    By nathanr_kamal in forum AWT / Swing
    Replies: 0
    Last Post: 06-24-2008, 11:33 AM

Tags for this Thread

Posting Permissions

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