Question

JAVA STRINGS AND CHARACTERS - USE SIMPLE CODING 1. Write a program that takes a string...

JAVA STRINGS AND CHARACTERS - USE SIMPLE CODING

1. Write a program that takes a string of someone's full name and prints it out last name first. You may use the available string manipulation methods. Example: "George Washington"

"Washington, George"

2. Write a program that will take a string of someone's full name, and break it into separate strings of first name and last name, as well as capitalize the first letter of each.

Example: "joseph smith", "Joseph" "Smith"

0 0
Add a comment Improve this question Transcribed image text
Answer #1
\color{blue}\underline{1:}

import java.util.Scanner;

public class FullNameChange {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.print("Enter full name: ");
        String first = in.next(), last = in.next();
        System.out.println(last + ", " + first);

        in.close();
    }
}

)#xxi::x: :i.T.1.1. rusos :: George Washington Washington, George Process finished with exit code 0

\color{blue}\underline{2:}

import java.util.Scanner;

public class FullNameChange2 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        System.out.print("Enter full name: ");
        String fullName = in.nextLine();
        String first = fullName.split(" ")[0], last = fullName.split(" ")[1];
        first = Character.toUpperCase(first.charAt(0)) + first.substring(1).toLowerCase();
        last = Character.toUpperCase(last.charAt(0)) + last.substring(1).toLowerCase();

        System.out.println(first + " " + last);

        in.close();
    }
}

name: Joseph Smith Process finished with exit code O

Add a comment
Know the answer?
Add Answer to:
JAVA STRINGS AND CHARACTERS - USE SIMPLE CODING 1. Write a program that takes a string...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • use Java and it must work for any name String Manipulator Write a program to manipulate...

    use Java and it must work for any name String Manipulator Write a program to manipulate Strings. Store your full name into one String variable. It must include first name, middle name, last name, cach separated by spaces. Spaces could vary. If you do not have a middle name make up one For example the string to be processed could be any of the following John Plain Doe John Plain Doc John Plain Doe Your program must be able to...

  • Write a program in java to read a string object consisting 300 characters or more using...

    Write a program in java to read a string object consisting 300 characters or more using index input Stream reader. The program should perform following operations. The String must have proper words and all kind of characters.(Use String class methods). a, Determine the length of the string count the number of letters in the strings , count the number of numeric object d. Calculate the number of special character e. Compute the ratio of the numeric to the total f....

  • Write a Java program that reads a series of strings from a user until STOP is...

    Write a Java program that reads a series of strings from a user until STOP is entered. Each input consists of information about one student at the ABC Professional School. The input consists of the student’s last name (the first 15 characters with extra blanks on the right if the name is not 15 characters long), the student’s number (the next 4 characters, all digits, a number between 1000 and 5999), and the student’s program of study (one character, either...

  • Write a Java program which takes a string as a user input. Create 2 functions. The...

    Write a Java program which takes a string as a user input. Create 2 functions. The first function expects a string as argument and returns void. It converts all upper case characters to lower case and converts all lower case characters to upper case. It then prints out the converted string to a console. The second function also expects a string as argument and returns void. It will find first charactor that is repeated exactly 2 times in the string....

  • Lab2: Processing Strings Part#1 – Counting Vows Assume s is a string of lower case characters....

    Lab2: Processing Strings Part#1 – Counting Vows Assume s is a string of lower case characters. Write a program that counts up the number of vowels contained in the string s. Valid vowels are: 'a', 'e', 'i', 'o', and 'u'. For example, if s = 'azcbobobegghakl', your program should print: Number of vowels: 5 Part#2 – Counting Bobs Assume s is a string of lower case characters. Write a program that prints the number of times the string 'bob' occurs...

  • Need Java help: 1. Create a Java program that accepts input String input from a user...

    Need Java help: 1. Create a Java program that accepts input String input from a user of first name. 2. Create a Java program that accepts input String input from a user of last name. 3. Concatenate the Strings in a full name variable and print to the console.

  • Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to...

    Problem 1: Dynamic Grocery Array Using Java to write a program that prompts the user to enter an item’s name for each position in the array. The program then prints uses a loop to output the array. Example 1: Banana 2: Orange 3: Milk 4: Carrot 5: Chips Banana, Orange, Milk, Carrot, Chips Problem 2: Print Characters in String Array    Declare a string array of size 5. Prompt the user enters five strings that are stored in the array....

  • 1. Write a program to input a list of names (strings) from the user and store...

    1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or by entering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For...

  • Write a program that uses String method regionMatches to compare two strings input by the user....

    Write a program that uses String method regionMatches to compare two strings input by the user. The program should prompt the user to enter two strings, the starting index in the first string, the starting index in the second string, and the number of characters to be compared. The program should print whether or not the strings are equal, (Ignore the case of the characters during comparison.) 四SAMPLE RUN #1: java StringCompare Highlight: None D Show Highlighted Only Interactive Session...

  • C programming 1 String Merging Write a program that reads two strings s1 and s2 from...

    C programming 1 String Merging Write a program that reads two strings s1 and s2 from the keyboard and merges them to a string s3. Strings s1 and s2 are statically allocated whereas s3 is dynamically allocated to fit exactly s1 and s2. The two original strings are no longer than 100 characters long. Use the following function to merge the two strings. char *stringMerge(char s1[], char s2 []); Example: Enter the first string: Hello world Enter the first string:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT