• Register
0 votes
26 views
I have a presentation about capitalize the first letter of each word of a sentence 
I write a program like that :
 public static void main(String[] args){
	 Scanner in = new Scanner(System.in);
         System.out.print("Input a Sentence: ");
	 String line = in.nextLine();
	 String upper_case_line = ""; 
         Scanner lineScan = new Scanner(line); 
         while(lineScan.hasNext()) {
             String word = lineScan.next(); 
             upper_case_line += Character.toUpperCase; 
         }
      System.out.println(upper_case_line); 
    }

But it gives some error:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
  symbol:   variable toUpperCase
  location: class java.lang.Character
	at javastackoverflow.NewClass1.main(NewClass1.java:15)
C:\Users\Hp\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 9 seconds)

What is the error ?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes
You can use trim method to take a upper case number after space:
 public static void main(String[] args){
	 Scanner in = new Scanner(System.in);
         System.out.print("Input a Sentence: ");
	 String line = in.nextLine();
	 String upper_case_line = ""; 
         Scanner lineScan = new Scanner(line); 
         while(lineScan.hasNext()) {
             String word = lineScan.next(); 
             upper_case_line += Character.toUpperCase(word.charAt(0)) + word.substring(1) + " "; 
         }
      System.out.println(upper_case_line.trim()); 
    }

Happy coding

 

11 6 4
34,950 points

Related questions

0 votes
1 answer 14 views
14 views
Problem: I'm utilizing Java to get a String contribution from the client. I'm attempting to make the principal letter of this info promoted. String name; BufferedReader br = new InputStreamReader(System.in); String s1 = name.charAt(0).toUppercase()); System.out.println(s1 + name.substring(1));
asked Feb 19 TeamScript 13.5k points
0 votes
1 answer 36 views
36 views
Problem: Is there a function built into Java that capitalizes the first character of each word in a String, and does not affect the others? Examples: jon skeet -> Jon Skeet miles o'Brien -> Miles O'Brien (B remains capital, this rules out Title Case) old mcdonald -> Old Mcdonald* *(Old McDonald would be find too, but I don't expect it to be THAT smart.)
asked Dec 3, 2020 Mashhoodch 13k points
0 votes
1 answer 42 views
42 views
I want to know a function built into Java that capitalizes the first character of each word in a String. It doesn’t affect the others?
asked Sep 28, 2020 Daniel Anderson 4k points
1 vote
1 answer 18 views
18 views
Problem: Hello all, I have a sample String. Let’s say it is "my name is gavin" As you can see there is no capital letter in my String. I want to make a program that can replace every first position of each word with a capital word. And the final output ... is enough, make things clear to you guys. So, my question is very simple. How can I capitalize the first letter of each word in Java?
asked Apr 8, 2020 Gavin 15.3k points
1 vote
1 answer 1 view
1 view
Problem: Can someone please help fix this uncaught error : python capitalize first letter of string
asked Mar 31 MUHAMMAD MUNEEB 83k points
1 vote
1 answer 3 views
3 views
Problem: How can I deal with this problem : javascript capitalize first letter of string
asked Mar 25 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 6 views
6 views
What can i do?
asked Jan 22 TeamScript 13.5k points
0 votes
1 answer 17 views
0 votes
1 answer 3 views
3 views
PROBLEM : Need your help to solve this >'how to get first letter of string java' ?
asked Mar 16 Samiur1 38.4k points