Exception in thread java programming error -


i trying run java program find if number palindrome or not @ time of compilation getting error message - exception in thread "main" java.lang.error: unresolved compilation problem: method must return result of type boolean.

below program code :

package testing; import java.util.scanner; public class palindromenumber {      public static void main(string[] args) {         system.out.println("enter number check if palindrome or not :");         int number1 = new scanner (system.in).nextint();         if(palindromecheck(number1)) {             system.out.println("number " +number1+ " palindrome.");         }         else {             system.out.println("number " + number1 + " not palindrome.");         }     }     public static boolean palindromecheck(int number) {     int palindrome = number;     int reverse = 0;     while (palindrome !=0) {         int remainder = palindrome % 10;         reverse = reverse * 10 + remainder;         palindrome = palindrome / 10;         if (number == reverse) {             return true;         }      return false; } } } 

what if number=0 @ begining? code won't return @ moment. return false, outside while loop.

public static boolean palindromecheck(int number) {     int palindrome = number;     int reverse = 0;     while (palindrome !=0) {         int remainder = palindrome % 10;         reverse = reverse * 10 + remainder;         palindrome = palindrome / 10;         if (number == reverse) {             return true;         }     }     return false; //note curly brace above. method return either true or false } 

Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -