私は学校のためにこのプロジェクトをやっています。
基本的に、フレーズを入力すると、プログラムはそれを特定の文字の数に分解して配列に入れ、最も出現する文字に分解します。
元。
I am not Santa
Santa lives in the north pole
Santa is not Canadian
a=10
b=0
c=1
など、プラス
most occuring=a
これが私のメインです:
import java.util.Scanner;
public class LetterDriver{
public static void main(String[] args){
String[] lines = new String[3];
Scanner scan = new Scanner(System.in);
System.out.println("enter any phrases, then press enter");
int pos = 0;
String tScan = " ";
while(tScan.length() > 0){
tScan = scan.nextLine();
lines[pos] = tScan;
pos++;
}
LetterProfile.printResults(tScan);//ERROR, I feel it's a syntax issue here, but I can't figure it out.
}
}
そしてこれは私の他のクラスです:
public class LetterProfile{
int cCount[] = new int [26];
public void countChars (String s){
s.toLowerCase();
char a = 'a';
for (int i =0;i < s.length();i++){
int pos = (int)s.charAt(i) -(int) a;
if ( pos >=0 && pos < 26){
cCount[pos]++;
}
}
}
public int mostOccur(){
int largest = 0;
int largestindex = 0;
for(int a = 0; a < 26; a++){
if(cCount[a] > largest){
largest = cCount[a];
}
}
return (largestindex);
}
public void printResults(){
System.out.println(this.mostOccur());
}
public void runProg(String a){
a.countChars();
System.out.println(mostOccur(a)); //ERROR
}
}
私はこれに約5時間取り組んできましたが、何も問題はありません。プログラムに必要な部分はすべてすでにそこにあると思いますが、もっとうまく整理する必要があります。
それは私にこれらのエラーを与えています:
2 errors found:
File: C:\Users\Mike\Desktop\LetterDriver.java [line: 14]
Error: method printResults in class LetterProfile cannot be applied to given types;
required: no arguments
found: java.lang.String
reason: actual and formal argument lists differ in length
File: C:\Users\Mike\Desktop\LetterProfile.java [line: 30]
Error: method mostOccur in class LetterProfile cannot be applied to given types;
required: no arguments
found: java.lang.String
reason: actual and formal argument lists differ in length