Please Help Me Debug This Java(source Code)program! It Can Be Compiled,but It Does Not Run!!!?

November 27th, 2009 by admin | Filed under Thread Debugging

***after i compiled this as javac go.java, it has no errors, but when I want to run this already as ” java go ” it cannot be run. there says Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException… 0 at go.main(go.java:3)
***here’s the source code: (please do help me debug and run this JAVA program please)
class go{
public static void main(String [] args){
String s = args[0];
int[] f = tally(s);
}
static int[] tally(String s){
int[] f = new int[26];
s = s.toUpperCase();
for(int i=0; i<s.length();i++){
char ch = s.charAt(i);
if (Character.isLetter(ch)){
int j = ch – 'A';
++f[j];
}
}
return f;
}
static void print(int[] f){
for(int j=0; j0)
System.out.println(ch +”: “+f[j]);
}
}
}

Related Posts:

tag_iconTags: | | | | | |

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

4 Responses to “Please Help Me Debug This Java(source Code)program! It Can Be Compiled,but It Does Not Run!!!?”.

  1. mjmg :

    look to this sample program:
    public class Test {
    public static void main(String args[]) {
    System.out.println(“Hello There “+ args[0] +” “+args[1]);
    }
    }
    To run this class after compiling it, you will specify two arguments e.g.
    java Test Joe Blogg
    It will print
    Hello There Joe Blogg where args[0] = Joe and args[1] = Blogg
    in ur program u r not passing any argument while executing it.
    as on the third line :- String s=args[0];
    if u will not pass any argument for array args[] then it will throw ArrayIndexOutOfBound exception. Hope u get it.

  2. DotnetGu :

    you need to type in java go , where is any number, the program needs a number to tally.

  3. iammisc :

    The problem is that your program is expecting an argument but you’re not passing in an argument. The line that is looking for an argument:

    public static void main(String [] args){
    String s = args[0]; <— Here you are looking for an argument

    Perhaps try something like “java go Whatever”.

  4. mc_barro :

    in the command line, try to run ur program as:
    java go “test”

Leave a comment.

To leave a comment, please fill in the fields below.

Powered by Yahoo! Answers