methods - Else without If error (Palindrome program) -


the program meant find if user input palindrome. in ispalindrome method keep getting stated error. , when fix 24 errors saying can't located multiple other variables. please help.

here code:

import java.util.scanner;  public class project4 {     public static void main (string [] args) {          string line = getinputline();         while (!isemptyline (line)) {             if (ispalindrome (line))                 system.out.println ("\"" + line +                     "\" palindrome , " + getpaltype (line));             else                 system.out.println ("\"" + line +                     "\" not palindrome");                 line = getinputline();              }             system.out.println ("end of prgram");         }      public static string getinputline () //ask user input , returns line     {         scanner scan = new scanner(system.in);         system.out.print("enter possible palindrome: ");         string getinputline = scan.nextline();         return getinputline;     }       public static boolean isemptyline (string str) // return true if paramater empty or false otherwise     {         if (line != null)         {             isemptyline = true;         }         else         {             isemptyline = false;         }     }      public static boolean ispalindrome (string str)// return true if str palindrome or false otherwise     {         int left = 0;         int right = line.length() - 1;         boolean okay = true;          while (okay && left < right){              char ch1 = line.charat(left);              if (!(character.isdigit(ch1) || character.isletter(ch1))){                  left ++;              else{                 ch2 = line.charat(right);             }                  if (!(character.isdigit(ch2) || character.isletter(ch2))){                     right --;                  else{                     ch1 = character.touppercase(ch1);                     ch2 = character.touppercase(ch2);                 }                 if (ch1 == ch2){                     left ++;                     right --;                  else{                     okay = false;                 }                 }             }         }     }     return okay; }  public static string getpaltype (string str)//determine type of palindrome , return either word/phrase/number. {     int num = 0;     int let = 0;     int length = line.length();      (int = 0; <= length; i++)     {         if (character.isdigit(line.charat(i)))             num++;         else if (character.isletter(line.charat(i)))             let++;     }      if (num > 0 && let == 0)     {         getpaltype = number;         return getpaltype;     }     else if (let > 0 && num == 0)     {         getpaltype = word;         return getpaltype;     }     else         getpaltype = phrase;         return getpaltype;      } } 

missing top starting bracket @

  if (ispalindrome (line)) 

you cannot use closing 1 line style if have 1 or other. add start bracket.

needs this:

while (!isemptyline (line)) {     if (ispalindrome (line)){         system.out.println ("\"" + line +             "\" palindrome , " + getpaltype (line));     }else{         system.out.println ("\"" + line +             "\" not palindrome");         line = getinputline();      } //since have 2 lines not 1 in else.     }     system.out.println ("end of prgram"); 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -