Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: String Manipulation | Reference Types and Strings
Java Data Types

bookChallenge: String Manipulation

In this challenge, you will practice manipulating strings by extracting and transforming specific parts of a Java String. This exercise will help you reinforce your understanding of reference types and common string operations, which are essential skills when working with user input or formatting output.

Suppose you are given a person's full name in the format First Last (for example, John Doe). Your task is to extract the first letter of each name part, convert them to uppercase, and print them together as the person's initials. If the input is John Doe, the output should be JD. You will use string methods such as split, charAt, and toUpperCase to accomplish this.

Opgave

Swipe to start coding

Write a method that extracts the initials from a full name string and returns them as an uppercase string. The main method should call this method and print the returned initials using the template: "Initials: AB" where "AB" are the initials.

  • Implement a method that takes a String parameter representing the full name and returns a string containing the initials in uppercase.
  • In the main method, call this method with the fullName variable and print the initials using the template: "Initials: AB" where "AB" are the initials.

Løsning

solution.java

solution.java

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 3
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

Can you show me an example input and expected output?

What should I do if the input has more than two names?

Can you explain how to use the split and charAt methods in this context?

close

Awesome!

Completion rate improved to 7.14

bookChallenge: String Manipulation

Stryg for at vise menuen

In this challenge, you will practice manipulating strings by extracting and transforming specific parts of a Java String. This exercise will help you reinforce your understanding of reference types and common string operations, which are essential skills when working with user input or formatting output.

Suppose you are given a person's full name in the format First Last (for example, John Doe). Your task is to extract the first letter of each name part, convert them to uppercase, and print them together as the person's initials. If the input is John Doe, the output should be JD. You will use string methods such as split, charAt, and toUpperCase to accomplish this.

Opgave

Swipe to start coding

Write a method that extracts the initials from a full name string and returns them as an uppercase string. The main method should call this method and print the returned initials using the template: "Initials: AB" where "AB" are the initials.

  • Implement a method that takes a String parameter representing the full name and returns a string containing the initials in uppercase.
  • In the main method, call this method with the fullName variable and print the initials using the template: "Initials: AB" where "AB" are the initials.

Løsning

solution.java

solution.java

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 2. Kapitel 3
single

single

some-alt