Write a program using Scanner and its nextLine method. The following is an example of how...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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(); If the user's input is shorter than 7 characters, print the message "The input is too short" and do no further processing. If the user's input is 7 characters or longer, perform the following operations. 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 two and last five characters of aLine and print the result. Print aLine in all upper case. If aLine has an odd number of characters, print "The line has an odd number of characters." Otherwise, print the two middle characters of aLine. Print the compare To 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. Print aLine with one character removed: The first 'e' 'E' 's' or 'S'. Note: sample output from my solution is in the attached text file. 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 two and last five characters would print Godotlroy was here, still waiting for Ki and printing aLine in all upper case would result in KILROY WAS HERE, BUT NOT GODOT You may use ONLY String's indexOf, charAt, length, compareTo, toUpperCase, toLowerCase, trim, equals, equalsIgnoreCase and substring methods. 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(); If the user's input is shorter than 7 characters, print the message "The input is too short" and do no further processing. If the user's input is 7 characters or longer, perform the following operations. 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 two and last five characters of aLine and print the result. Print aLine in all upper case. If aLine has an odd number of characters, print "The line has an odd number of characters." Otherwise, print the two middle characters of aLine. Print the compare To 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. Print aLine with one character removed: The first 'e' 'E' 's' or 'S'. Note: sample output from my solution is in the attached text file. 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 two and last five characters would print Godotlroy was here, still waiting for Ki and printing aLine in all upper case would result in KILROY WAS HERE, BUT NOT GODOT You may use ONLY String's indexOf, charAt, length, compareTo, toUpperCase, toLowerCase, trim, equals, equalsIgnoreCase and substring methods.
Expert Answer:
Answer rating: 100% (QA)
Heres a Java program that uses the Scanner class and its nextLine method to implement the specified ... View the full answer
Related Book For
Accounting Information Systems basic concepts and current issues
ISBN: 978-0078025334
3rd edition
Authors: Robert Hurt
Posted Date:
Students also viewed these programming questions
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
can someone solve this Modern workstations typically have memory systems that incorporate two or three levels of caching. Explain why they are designed like this. [4 marks] In order to investigate...
-
Under which of the following circumstances would an auditor be most likely to intensify an challenging examination of a $500 imprest petty cash fund a. Reimbursement occurs twice each week. b. The...
-
Write the expression for Kc for the following reactions. In each case indicate whether the reaction is homogeneous or heterogeneous.
-
What refers to countries trying to gain independence from their reliance on another country for goods or services; an example of this is the U.S. and the microchip fabrication business with what?
-
Consider the situation of Example 12.10. Rather than shorting a futures contract, the U.S. firm could borrow \(500 /\left(1+r_{G} ight)\) euros (where \(r_{G}\) is the 90-day interest rate in...
-
The following trial balance has been extracted from Carol Ltd as at 30 April 2012: Additional information: 1. Stock at 30 April 2012 was valued at 140,000. 2. Depreciation for the year of 28,000 is...
-
1. Using MATLAB, plot the three elements of the strain vector when the above material is oriented at (1) 0 and (2) at 30. This is accomplished by incrementally applying stress (i.e., 5 psi, 10 psi,...
-
The Albertville City Council decided to pool the investments of its General Fund with Albertville Schools and Richwood Township in an investment pool to be managed by the city. Each of the pool...
-
You are asked to test an underground pipe with clean water steadily flowing through. The pipe starts with a large cross sectional area of 450 cm^2 and after a few meters the presence of debris...
-
Explain why location decisions are important.
-
Explain what scheduling involves and the importance of good scheduling.
-
Identify some of the main reasons organizations need to make location decisions.
-
Identify the determinants of quality.
-
Explain the benefit of cross-docking.
-
Let m be a Let m be a fixed natural number, and suppose that Pm is a polynomial with rational coefficients (in other words, Pm (x) = ax, where ai, 0 i m, are rational numbers). Prove that either or...
-
1. Following are information about Alhadaf Co. Cost incurred Inventory Purchases Sales Adverting expense Salary Expense Depreciation Beginning Inventory Ending Inventory Amount 118,000 350.000 90,000...
-
Journalize the transactions of Luna Technology Solutions. Include an explanation with each journal entry. Use the following accounts: Cash; Accounts Receivable; Supplies; Prepaid Advertising; Land;...
-
As the manager of Yum Yum Thai, you must deal with a variety of business transactions. Provide an explanation for the following transactions: a. Debit Equipment and credit Cash. b. Debit Saelim,...
-
Schuster Services reported assets of $800 and equity of $480. What is Schuster Services debt ratio? a. 60% b. 40% c. 67% d. Not enough information is provided.
Study smarter with the SolutionInn App