HW08

Ace your homework & exams now with Quizwiz!

write a main method that uses this method and displays the final palindrome to the screen.

Public static void main(String[ ] args) { system.out.println(keepAskForPalindromLoop(inputString)); }

write a main method that uses this method and displays the final palindrome to the screen.

Public static void main(String[] args) { system.out.println(keepAskFoPalindromLoop(inputString)); }

Write a method named rowOfStars that takes a single integer parameter n and returns a String with that many stars in it. For example, calling the method with a value of 3 would cause the String "***" to be returned.

Public static void rowOfStars (int n) { int i = 1; String output = ""; while ( i <= n) { output = output + "*"; i = i + 1; } system.out.println(output); }

Using the method you wrote for the previous question, write a method that takes a single integer parameter n and prints a triangle of stars to the screen that has a height and base size equal to n. For example, calling the method with a value of 4 will produce the triangle: * ** *** ****

Public static void triangleOfStars (int n) { int j = 1; While (j <= n) { system.out.println(rowOfStars(j)); } }

Using the methods you wrote for the above question, write a method that takes a Scanner as an input parameter and returns a String as a result. The method should print a prompt to the screen asking the user to enter a palindrome. It should then test the input. If it is not a palindrome, it should print an error message and continue asking for a palindrome until the user provides one. Once a palindrome has been input, the method should return it.

public static String keepAskForPalindromeLoop (Scanner) { Import java.util.Scanner; Scanner.in = new Scanner (System.in); system.out.print("enter a palindrome."); String inputString = in.nextLine(); while ( ! palindromeTest(inputString) ) { system.out.println( "Error: Please enter a palindrome."); } return inputString; }

write a method that takes a Scanner as an input parameter and returns a String as a result. The method should print a prompt to the screen asking the user to enter a palindrome. It should then test the input. If it is not a palindrome, it should print an error message and continue asking for a palindrome until the user provides one. Once a palindrome has been input, the method should return it.

public static String keepAskForPalindromeLoop (Scanner) { Import java.util.Scanner; Scanner.in = new Scanner (System.in); system.out.print("enter a palindrome."); String inputString = in.nextLine(); while ( ! palindromeTest(inputString) ) { system.out.println( "Error: Please enter a palindrome."); } return inputString; }

Write a method that takes a String as input and returns the reverse of that String.

public static String stringReverse( String inputString) { int i = 1; reverseString = " " ; reverseString = reverseString + inputString.charAt( inputString.Length()-i); return reverseString ; }

write a second method that uses the first method to test whether or not an input String is a palindrome. Your method should return true if the String is a palindrome, and false otherwise.

public static boolean palindromeTest ( String inputString) { if (stringReverse.inputString()equals(inputString)) { return true; } else { return false; } }

write a main method that tests your method with a variety of Strings that should return true and false values.

public static void main(String [] args) { Import java.util.Scanner; Scanner.in = new Scanner (System.in); system.out.println(" Type a string.") String inputString = in.nextLine(); return palindromeTest(inputString); }


Related study sets

AP Chemistry Unit 5 Progress Check

View Set

U.S. History Chapter 2 Section 4

View Set

Tyler's Astronomy Glossary (O-Z)

View Set

MGMT-464: Chapter 8 - Group and Teams

View Set

Chapter 46: Management of Patients With Gastric and Duodenal Disorders 3

View Set