| | |
trouble with looping
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 0
hey guys.
i'm having trouble with looping a program.
my assignment is to get the user to input a string and then display it backwards.
i've successfully done this, but it's supposed to ask if you want to run the program again, and that's where my program fails.
it completely skips over the for loop after the first time it's run.

help, anyone?
pleaseee?
i'm having trouble with looping a program.
my assignment is to get the user to input a string and then display it backwards.
i've successfully done this, but it's supposed to ask if you want to run the program again, and that's where my program fails.
Java Syntax (Toggle Plain Text)
public class backwardstring { public static void main (String[]args) { int choice1 = 1; String string; final int arraylimit = 30; Scanner keyboard = new Scanner (System.in); char[] character = new char[arraylimit]; int i = 0; do { System.out.println("Enter a word or sentence:"); string = keyboard.nextLine(); character = string.toCharArray(); for (i = character.length - 1; i >= 0; i--) { System.out.print(character[i]); } System.out.println(""); System.out.println("Would you like to enter another word or sentence?(Y(0)/N(1)"); choice1 = keyboard.nextInt(); i = 0; } while(choice1 == 0); } }
it completely skips over the for loop after the first time it's run.

help, anyone?
pleaseee?
![]() |
Similar Threads
- ArrayList looping question (Java)
- trouble in displaying records in the same page from db. (PHP)
- Problem using exceptions and looping (Java)
- Network help (Python)
- Help with looping through a vector (C++)
- Trouble with a function that asks a user for a number. (C)
- Help with Perl script to verify IP addresses (Perl)
- single-dimensional array trouble (C++)
- palindrome (Java)
- Creating Functions to print to screen. (C++)
Other Threads in the Java Forum
- Previous Thread: thinking of starting
- Next Thread: Why my executable jar file cant write a text file
Views: 298 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application arguments array arrays automation awt bidirectional binary birt bluetooth calculator chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse editor error errors event exception expand file fractal game givemetehcodez graphics gui guidancer helpwithhomework html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jmf jni jpanel julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie number object oracle plazmic print problem program programming project recursion scanner screen server set signing size smart sms smsspam socket sort sql string subclass support swing test threads time tree webservices windows





