java - palindrome - how to make main method call the boolean method? -
java - palindrome - how to make main method call the boolean method? -
i trying user input , determine if word palindrome or not. main method should of print statements placed.
package help; import java.util.scanner; public class help { public static scanner user_input; public static void main(string[] args, iterable<string> lines) { system.out.print("enter word: "); user_input=new scanner(system.in); } public static boolean istpalindrom(char[] word) { int i1 = 0; int i2 = word.length - 1; while (i2 > i1) { if (word[i1] != word[i2]) { homecoming false; } ++i1; --i2; } homecoming true; } } i want say
class="lang-none prettyprint-override">if true system.out.println(the word palindrome.) else system.out.println(the word not palindrome.) i not sure how go this.
your palindrome test looks 1 time prepare indentation, it's named oddly in english. have scanner, can lines of input. phone call tochararray() on string char[] like
public static void main(string[] args) { system.out.print("enter word: "); scanner input = new scanner(system.in); while (input.hasnextline()) { string line = input.nextline(); if (ispalindrome(line.tochararray())) { system.out.printf("the word %s palindrome.%n", line); } else { system.out.printf("the word %s not palindrome.%n", line); } } } public static boolean ispalindrome(char[] word) { int i1 = 0; int i2 = word.length - 1; while (i2 > i1) { if (word[i1] != word[i2]) { homecoming false; } ++i1; --i2; } homecoming true; } java
Comments
Post a Comment