- #1
zzoo4
- 42
- 0
Like this is my program to change the words around in order. Like First two words go to the back. What I am having trouble is, How do I capitalize the first at the results section after
the words order have changed??
This is my program.
import java.util. Scanner;
public class Starwars{
public static void main (String[]args){
//Declare Variables Section
int length, position=0;
String phrase, phrase2, phrase3;
Scanner input= new Scanner(System.in);
//Obtain Input From Section
System.out.println ("Enter your phrase: ");
phrase= input.nextLine();
length= phrase.length();
System.out.println (phrase);
//Perform Calculations Section
int i=0;
int i2=0;
while (i<length){
if (phrase.substring(i,i+1).equals(" ")){
i2++;
if (i2==2){
position=i;
}
}
i++;
}
phrase2=phrase.substring(position);
phrase3=phrase.substring(0,position);
System.out.println ("Yoda: " + phrase2 + ", " + phrase3);
}
}
the words order have changed??
This is my program.
import java.util. Scanner;
public class Starwars{
public static void main (String[]args){
//Declare Variables Section
int length, position=0;
String phrase, phrase2, phrase3;
Scanner input= new Scanner(System.in);
//Obtain Input From Section
System.out.println ("Enter your phrase: ");
phrase= input.nextLine();
length= phrase.length();
System.out.println (phrase);
//Perform Calculations Section
int i=0;
int i2=0;
while (i<length){
if (phrase.substring(i,i+1).equals(" ")){
i2++;
if (i2==2){
position=i;
}
}
i++;
}
phrase2=phrase.substring(position);
phrase3=phrase.substring(0,position);
System.out.println ("Yoda: " + phrase2 + ", " + phrase3);
}
}