CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
MBC
Level 14
Apeldoorn
  • 14.07.2019
  • 973views
  • 6comments

Problem with last test requirement

Question about the task Going national
Java Syntax,  Level 8,  Lesson 11
Archived

Write a program that reads a string from the keyboard.
The program should change the first letter of each word to uppercase.
Display the result on the screen.

Example input:
sam i am.

Example output:
Sam I Am.

Requirements:
  • The program should display text on the screen.
  • The program should read a string from the keyboard.
  • The program should change the first letter of each word to uppercase.
package com.codegym.task.task08.task0823; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* Going national */ public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String s = reader.readLine(); char[] m = s.toCharArray(); int size = m.length; m[0] = (char) (m[0] - 32); int i = 1; while (i != size) { if(m[i] == ' ') { m[i + 1] = (char) (m[i + 1] - 32); } i++; } //System.out.println(s); System.out.println(m); } }
0
Comments (6)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Dmitriy Bursa
Level 27 , Kyiv, Ukraine
14 July 2019, 17:18
try to solve through String.split, String.toUpperCase , String.substring
0
MBC
Level 14 , Apeldoorn, Netherlands
14 July 2019, 17:22
Is there a way to do it where I can split the string after reading it into variable s and then, convert it into a char array?
0
Dmitriy Bursa
Level 27 , Kyiv, Ukraine
14 July 2019, 17:24
first step
String[] array = s.trim().split("\\s+");
next: get 1st symbol, to uppercase it, make string (use substring) in the loop
+2
Dusernajder
Level 20 , Budapest, Hungary
15 July 2019, 09:09
What are the names of these kinds of arguments? How can I search it up? (\\s+)
0
Dmitriy Bursa
Level 27 , Kyiv, Ukraine
15 July 2019, 18:20
it's a regular expression look this (note this: 4. Using regular expressions with String methods) https://www.vogella.com/tutorials/JavaRegularExpressions/article.html s.split("regex") in the table, regex-value is \\s+ and this https://codegym.cc/groups/posts/regex-java
+2
Dusernajder
Level 20 , Budapest, Hungary
18 July 2019, 06:57
Thank you indeed.
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.