So I am making a program of sorts where the computer asks for you to type something, and it will determine if it has an odd or even amount of characters, by either making the phrase reversed or by cutting it up a little. I already made that part, but how can I connect the variable "odd" and "even" with the loop? I am thinking about using an if statement, but I don't know how to set it up. Can someone help?
System.out.println("Enter a phrase you like");
String phrase = input.nextLine();
int length = phrase.length();
int odd;
for(int d = 0; d < length; d+=2)
{ //Starts the loop
System.out.print((phrase.charAt(d)));
}//ends loop
int even;
for(int a = length-1; a>=0; a--)
{ //Starts the loop 2
System.out.print((phrase.charAt(a)));
}//ends loop
Aucun commentaire:
Enregistrer un commentaire