Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Write a public class call FunnyWord. class FunnyWord must have a main method. what it does: 0. prompt user for a String 1. read

JAVA Write a public class call FunnyWord. class FunnyWord must have a main method. what it does: 0. prompt user for a String 1. read a String from the user 2. print whether the String is funny or not 3. continue until user enters the word "end" The String is funny if it looks the same read from left to right or right to left. In order to pass all tests you must find funny phrases when spaces, punctuation and case are ignored (look at the examples). HINT: you could use the method replaceAll from String in order to delete all the punctuation marks. For example: str.replaceAll(";", ""); returns a string where all semicolons have been replaced by nothing. or you could use str.replaceAll("\\W","") which replaces all punctuation marks you may also need other methods of String: toLowerCase(): returns another String in lower case length(): gives you the length of the String you can build a String character by character this way: char c; String rr; rr = rr + c; //adds the c at the end of rr here is a piece of code that uses some of these methods: public class Traverse{ public static void main(String [] aaa){ String ss = "x y z a b.?/;:'[{]} c defgh"; ss = ss.replaceAll("\\W",""); String new1 = ""; String new2 = ""; for (int i = 0; i < ss.length(); i++){ new1 = new1 + ss.charAt(i); new2 = ss.charAt(i) + new2; } System.out.println(new1); System.out.println(new2); } } Notice: you cannot use any method called "reverse". That is considered forbidden knowledge. 

Examples

% java FunnyWord Enter a String: Anna

funny!

Enter a String: AnnA AnnA

funny!

Enter a String: A man, a plan, a canal: Panama.

funny!

Enter a String: foo

that is not funny

Enter a String: Annax

that is not funny

Enter a String: end

that is not funny

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

Step: 3

blur-text-image

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

1. How do most insects respire ?

Answered: 1 week ago

Question

Who is known as the father of the indian constitution?

Answered: 1 week ago

Question

1.explain evaporation ?

Answered: 1 week ago

Question

Who was the first woman prime minister of india?

Answered: 1 week ago

Question

Explain the concept of going concern value in detail.

Answered: 1 week ago

Question

=+ What would it look like? Who should deliver it?

Answered: 1 week ago