0% found this document useful (0 votes)
286 views

Exercises Java

This document contains instructions for two Java string exercises. The first asks the user to write a program that takes a string as input and prints it in a diamond shape pattern, with the longest string being in the middle and getting progressively shorter on either side. The second asks the user to write a method to check if a string is a palindrome by comparing the first and last characters, then the second and second to last, and so on, ignoring case, punctuation and spaces. It also asks the user to test the method by prompting the user for a string input and notifying if it is a palindrome.

Uploaded by

dj_jovica
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
286 views

Exercises Java

This document contains instructions for two Java string exercises. The first asks the user to write a program that takes a string as input and prints it in a diamond shape pattern, with the longest string being in the middle and getting progressively shorter on either side. The second asks the user to write a method to check if a string is a palindrome by comparing the first and last characters, then the second and second to last, and so on, ignoring case, punctuation and spaces. It also asks the user to test the method by prompting the user for a string input and notifying if it is a palindrome.

Uploaded by

dj_jovica
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Java Exercises Strings & StringTokenizer 1.

. Write a program that reads a string and then prints a diamond shaped array based on the characters of the string. As an example, if the string has the value "SAMPLE", then the program should print the pattern S SAS SAMAS SAMPMAS SAMPLPMAS SAMPLELPMAS SAMPLPMAS SAMPMAS SAMAS SAS S The program should work for a string up to ten characters long. If a user supplies a string that is longer than ten characters, the program should use only the first ten characters in forming the pattern. 2. A palindrome is a string that reads the same both forward and backward. Examples of palindromes are "radar" and "31413". (a) Write a boolean-valued method isPalindrome that has a single String parameter. The method should return true if and only if its parameter is a palindrome. (b) Modify your method so that it ignores cases of letters, punctuation marks, and blanks in making a decision about whether or not a string is a palindrome. For example, the string: "A man, a plan, a canal: Panama!" should be taken to be a palindrome. Write a program that prompts the user for a string and notifies the user if it is a palindrome.

You might also like