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

i compiled this as javac yes.java , and it does compiled! but when i run it as yes java "test" ,it goes back again to compilation! there's no output on the screen that I am waiting to view from it..Help me please to run this program and to see the output! Maybe there's a problem with my codes. Please debug also! :-D


Here's the java source code(program):


class yes{
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 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; j char ch = (char)(j+'A');
if (f[j]>0)
System.out.println(ch +": "+f[j]);
}
}
}

2007-07-10 01:55:02 · 4 answers · asked by mjmg 1 in Computers & Internet Programming & Design

4 answers

It runs just fine.

It doesn't produce any output because you only call "tally()" from main() -- print() is never called.

Change your main() from:

String s = args[0];
int[] f = tally(s);

... to:

String s = args[0];
int[] f = tally(s);
print(f);

... and you should see the output you desire.

2007-07-10 03:04:46 · answer #1 · answered by McFate 7 · 0 0

Hmmm...Sir u need to call the print(f) function in main method.There is nothing wrong in ur program.You are not telling any thing to print on console for the JVM.U wrote the method print(..)out side the class u need to explicitly call that method in ur main(...).
public static void main(String [] args){
String s = args[0];
int[] f = tally(s);
print(f);

}


..........

Its works fine.
All teh best.

2007-07-11 11:05:29 · answer #2 · answered by Naina 1 · 0 0

A nice and neat version:

public static void main(String args[])
{print(tally(args[0]));}

2007-07-13 01:56:04 · answer #3 · answered by eoin2000 1 · 0 0

numbers[index] = inputFile.nextInt(); while (numbers[index] != 0) { index++; numbers[index] = inputFile.nextInt(); } change that code into while(inputFile.hasNextInt()) { number[index] = inputFile.nextInt(); index++; }

2016-05-22 05:12:45 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers