Quantcast
Channel: java Syntax error on token "(", ; expected - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Matthew Champion for java Syntax error on token "(", ; expected

$
0
0

As stated by ratchet freak, you need to move the function out of main. The function itself belongs to the Assignment1 class and as such needs to be:

import javax.swing.JOptionPane;public class Assignment1{    public static void main(String args[])    {        String input = JOptionPane.showInputDialog("Enter a string");        if (istPalindrome(input))        {            JOptionPane.showMessageDialog(null,input+"is a palindrome");        }        else{            JOptionPane.showMessageDialog(null ,input +"is not a palindrome");        }    }    public static boolean istPalindrome(String a)/*error is here*/    {        char[] charArray = a.toCharArray();        int i1 = 0;        int i2 = a.length() - 1;        while (i2 > i1) {            if (charArray[i1] != charArray[i2]) {                return false;            }++i1;            --i2;        }        return true;    }}

I've also changed the variable "word" over to "a" (for the statements word.toCharArray() and word.length()) due to the fact that there is no "word" variable in scope within that function.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>