Sherwin Roy
New Member
- Joined
- Nov 12, 2010
- Messages
- 13
- Reaction score
- 0
- Points
- 1
i want to create a program that will prompt the user to input a phrase or sentence and make uppercase all the first letter of every word.
for example:
INPUT: hello world! what a beautiful day!
OUTPUT: Hello World! What A Beautiful Day!
my code is like this but this is very bad! so many errors!
import java.util.Scanner;
public class uppercase {
public static void main (String[]args){
Scanner sherwin=new Scanner(System.in);
System.out.println("Enter the phrase:");
String phrase=sherwin.next();
int i=0;
upper(i,phrase);
for(i=0;i<phrase.length();i++){
if((phrase.charAt(0))==' ')
upper(i+1,phrase);
}
System.out.println(phrase);
}
static void upper(int a,String word){
word=(word.charAt(a)).toUpperCase;
}
}
those who can give me a perfect answer will be chosen as the best answer. thanks!
for example:
INPUT: hello world! what a beautiful day!
OUTPUT: Hello World! What A Beautiful Day!
my code is like this but this is very bad! so many errors!
import java.util.Scanner;
public class uppercase {
public static void main (String[]args){
Scanner sherwin=new Scanner(System.in);
System.out.println("Enter the phrase:");
String phrase=sherwin.next();
int i=0;
upper(i,phrase);
for(i=0;i<phrase.length();i++){
if((phrase.charAt(0))==' ')
upper(i+1,phrase);
}
System.out.println(phrase);
}
static void upper(int a,String word){
word=(word.charAt(a)).toUpperCase;
}
}
those who can give me a perfect answer will be chosen as the best answer. thanks!