Question

In: Computer Science

Write a program call FancyMyName which asks you to write a program that tests the usage...

Write a program call FancyMyName which asks you to write a program that tests the usage of different methods for working with Strings.

This program will ask the user to enter their first name and their last name, separated by a space.

Read the user's response using Scanner. Separate the input string up into two strings, one containing the first name and one containing the last name. You can accomplish this by using the indexOf() hint*** find the position of the space, and then using substring() to extract each of the two names. Also output the number of characters in each name (first & last) and output the user's initials. The initials are the first letter of the first name together with the first letter of the last name

A sample run of the program should look something like this:

Please enter your first name and last name, separated by a space?

You entered the name: Steve Henry

Your first name is Steve: has 5 characters

Your last name is Henry: has 5 characters

Your initials are: SH

Solutions

Expert Solution

import java.util.Scanner;

public class FancyMyName1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String first, last;
        System.out.println("Please enter your first name and last name, separated by a space?");
        System.out.print("You entered the name: ");
        first = scanner.next();
        last = scanner.next();

        System.out.println("Your first name is "+first+": has "+first.length()+" characters");
        System.out.println("Your first name is "+last+": has "+last.length()+" characters");

        System.out.println("Your initials are: "+first.charAt(0)+last.charAt(0));
    }
}


Related Solutions

You will write a program in Scheme which compares the accuracy of two medical tests for...
You will write a program in Scheme which compares the accuracy of two medical tests for diagnosing a particular disease. The input to your program will be a list of data about a collection of patients specifying Whether the patient has the disease Whether the result of test 1 was positive Whether the result of test 2 was positive The input format will be a sequence of entries of this form: A positive integer, which is the number of the...
Write a program in which, you define and call each of the following functions, note that...
Write a program in which, you define and call each of the following functions, note that YOU CANNOT USE ARRAY NOTATION IN ANY FUNCTION AT ALL IN THIS EXERCISE, ONLY USE POINTER NOTATION TO MANIPULATE ARRAYS IN THE FUNCTIONS: 1. function read_array, that takes an array of 6 doubles and prompts the user to fill it through the keyboard. 2. function reverse_array, that takes an array of 6 doubles and reverses its contents. 3. function swap_arrays, that takes two arrays...
Write a design algorithm and a python program which asks the user for the length of...
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2...
// JavaLanguage . You need to write a program that asks the user for an array...
// JavaLanguage . You need to write a program that asks the user for an array size, and then asks the user to enter that many integers. Your program will then print out the sum , average, largest and smallest of the values in the array.
URGENT write a c++ program which asks the user to enter a positive number which is...
URGENT write a c++ program which asks the user to enter a positive number which is less than or equal to 9. Do not let the user continue until he or she enters a number within range. once a valid number is entered, multiply it by itself. if the resulting number is even, display a message with the number followed by the words even. If it is odd, display the number followed by the words is odd. must use a...
Use MIPS write an assembly program which asks the user to enter 3 number. The program...
Use MIPS write an assembly program which asks the user to enter 3 number. The program then sorts these numbers, the prints them from largest to smallest.
MATLAB Write a script which asks the user of the program to provide an initial horizontal...
MATLAB Write a script which asks the user of the program to provide an initial horizontal position, initial vertical position, initial velocity, and angle. Create a time vector spanning from zero seconds to 100 seconds incremented at 0.01 seconds. Call the function that you created in the previous problem to calculate the trajectory and velocities of the projectile. Find the maximum height of the projectile and the time at which it reaches that point. Write a neat sentence stating what...
Write a python program which asks the user to enter a positive number that is greater...
Write a python program which asks the user to enter a positive number that is greater than 30 called, “num2” and then does the following: o 1) Print all numbers between 1 and “num2” that are divisible by 2 and 3. o 2) Print all numbers between 1 and “num2” that are either divisible by 6 or 7. o 3) Print all numbers between 1 and “num3” that is not divisible by 5
In C++ Write a program which asks the user his/ her major, stores it in a...
In C++ Write a program which asks the user his/ her major, stores it in a variable called major, then asks What is your GPA? and stores it in a variable called gpa. Next, ask a question based on the answers from the previous two questions. For example: What is your major? computer science What is your gpa? 3.52 computer science is very hard; why do you think you have a gpa of 3.52?
Write a java program which asks the user to enter name and age and calls the...
Write a java program which asks the user to enter name and age and calls the following methods: printName(): Takes name as parameter and prints it 20 times using a while loop. printAge(): Takes age as parameter and prints all the numbers from 1 up to age. Write a java program that will print first 10 multiples of 3 in a single line.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT