Java 如何解决';。类别';预期错误?
目前,我在第40行有一个错误-“.class”预期值。非常感谢您的帮助Java 如何解决';。类别';预期错误?,java,Java,目前,我在第40行有一个错误-“.class”预期值。非常感谢您的帮助 import java.io.*; // For File class and FileNotFoundException import java.util.Scanner; //For the Scanner class import javax.swing.JOptionPane; // For the JOptionPane class /** * Write a description of class P
import java.io.*; // For File class and FileNotFoundException
import java.util.Scanner; //For the Scanner class
import javax.swing.JOptionPane; // For the JOptionPane class
/**
* Write a description of class PartB here.
*
* @Hubble, Kieran
* @Version 0.1
*/
public class PartB
{
public static void main(String[] args) throws FileNotFoundException
{
File file; //for file input
Scanner inputFile; //for file input
String fileName; //to hold a file name
String paragraph; //to extract the letter frequencies
//get a file name from the user.
fileName = JOptionPane.showInputDialog("enter " + " the name of the file");
//attempt to open the file.
try
{
file = new File(fileName);
inputFile = new Scanner(file);
JOptionPane.showMessageDialog(null, "the file was found.");
// read the input file, processing data one line at a time
while(inputFile.hasNext())
{
String str = inputFile.nextLine();
System.out.println(str);
}
//create an Output file
PrintWriter outputFile = new PrintWriter("crackedcode.txt");
while(paragraph.length() > 0)
// error is occurring on the next line (line 40)
int[]; letterCount = new int[26];
for (int count = 0; count < paragraph.length; count++) {
String current = paragraph[count];
char[] letters = current.toCharArray();
}
for (int count2 = 0; count2 < letters.length; count2++) { char lett = letters[count2]; if ( (lett >= 'A') & (lett <= 'Z') ) {
letterCount[lett - 'A']++;
}
}
for (char count = 'A'; count <= 'Z'; count++) {
System.out.print(count + ": " +
letterCount[count - 'A'] +
" ");
}
System.out.println();
// close the input file
inputFile.close();
}
catch (FileNotFoundException e)
{
JOptionPane.showMessageDialog(null, "file not found.");
}
JOptionPane.showMessageDialog(null, "done.");
System.exit(0); //terminate program
}
}
import java.io.*;//对于文件类和FileNotFoundException
导入java.util.Scanner//对于Scanner类
导入javax.swing.JOptionPane;//对于JOptionPane类
/**
*在这里写下PartB类的描述。
*
*@哈勃,基兰
*@Version 0.1
*/
公共类PartB
{
公共静态void main(字符串[]args)引发FileNotFoundException
{
File File;//用于文件输入
Scanner inputFile;//用于文件输入
字符串文件名;//保存文件名
字符串段落;//提取字母频率
//从用户处获取文件名。
fileName=JOptionPane.showInputDialog(“输入“+”文件名”);
//尝试打开该文件。
尝试
{
文件=新文件(文件名);
inputFile=新扫描仪(文件);
showMessageDialog(null,“找到文件”);
//读取输入文件,一次处理一行数据
while(inputFile.hasNext())
{
String str=inputFile.nextLine();
系统输出打印项次(str);
}
//创建一个输出文件
PrintWriter outputFile=新的PrintWriter(“crackedcode.txt”);
while(段落长度()>0)
//下一行(第40行)发生错误
int[];letterCount=新int[26];
for(int count=0;count<段落长度;count++){
当前字符串=段落[计数];
char[]字母=current.toCharArray();
}
对于(int count2=0;count2='A')&(lett删除分号
int[]; letterCount = new int[26];
应该是
int[] letterCount = new int[26];
此外,还需要用{}
将while的块(从其上方的行)包装起来,并删除分号
int[]; letterCount = new int[26];
应该是
int[] letterCount = new int[26];
另外,你需要用{}
来包装while的块(从上面的一行开始),JavaScript和Java是完全不同的东西。请重新标记你的问题。JavaScript和Java是完全不同的东西。请重新标记你的问题。非常感谢!我会给它拍照非常感谢!我会给它试一试