Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write in JAVA code: Problem 1: Numbers with embedded dashes play a huge role in our lives. Think of your phone number, or Social Security

Write in JAVA code:

Problem 1:

Numbers with embedded dashes play a huge role in our lives. Think of your phone number, or Social Security number. Write a program that uses a Scanner to take a single user input. You may assume this input contains no spaces, and consists of any number of digits with two dashes. Use only String's indexOf, lastIndexOf and substring methods. Sample input might be

123-45-6789

or

919-555-1212

Your program should remove the dashes and print the digits. The output for the above input would be

123456789

and

9195551212

Problem 2:

Write a program using Scanner and its nextLine method. The following is an example of how to use nextLine

Scanner kybd = new Scanner(System.in);

System.out.println("Enter a line of text");

String aLine = kybd.nextLine();

You may assume that the user input has at least 7 characters.

Print either "the original String has no leading or trailing whitespace" or "the original String has leading or trailing whitespace." (Hint: the trim method will be a good start, but you'll need more.)

Swap the first three and last four characters of aLine and print the result.

Print aLine in all upper case.

Print the compareTo results of comparing aLine in all lower case with the original aLine. (This will be a number.)

Print whether the first half of aLine is the same as the last half of aLine except for case.

Note: treat each of these steps as an independent action operating on the original input. So if the original input was

kilroy was here, but not godot

swapping the first three and last four characters would print

odotroy was here, but not gkil

and printing aLine in all upper case would result in

KILROY WAS HERE, BUT NOT GODOT

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

Students also viewed these Databases questions