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.
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?
:'(