English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

While compiling its not showing any error. Program is :

public class Strn
{

public static void main(String s)
{
int i, len = s.length();
String results = "";
for (i = (len - 1); i >= 0; i--)
{

char w=s.charAt(i);
results = results + w ;
}

System.out.println(results);}

}

2006-08-14 01:38:16 · 4 answers · asked by Anonymous in Computers & Internet Programming & Design

4 answers

oh guys come on

check the argument with main method it should be
main(String s[]) or main(String[] s)

the reason why it compiles well because u are overriding the main function..

2006-08-14 02:02:21 · answer #1 · answered by kanna 3 · 1 0

I did not read through all the code, so there could be more things wrong with this... but in java, length of an array is a public number and not a method.
So s.length() is wrong
It should be s.length

The java compiler is cribbing about the lenth() method not being available. I think thats a misconception people with prior exposure to C++ bring to java.

2006-08-14 08:46:55 · answer #2 · answered by Neil 5 · 0 1

I am usually successful at Googleing the error. Sun has so many bugs in their Java platform it is unreal. I recently had to add registry entries to get some Java to work. Here is the link to what i googled this time. Maybe it will help.

2006-08-14 08:45:54 · answer #3 · answered by Just Another Guy 4 · 0 1

check out the class name u r getting after compiling and also see that u r file name and the main prg must be same

2006-08-14 08:41:45 · answer #4 · answered by ch_nagarajind 3 · 0 1

fedest.com, questions and answers