java程序里的一个小错误,帮我看看(提示每10行需要']')

来源:百度知道 编辑:UC知道 时间:2024/06/04 09:01:58
import java.io.*;
class nb{
static int a[];
static char b;
public static void main(String args[]) throws IOException{

int a=new int [20];

for(int i=0;i<20;i++){
int a[i] =(int)System.in.read();
System.out.print(a[i]+" ");
}
}
}

import java.io.*;

class nb
{
static int a[];

static char b;

public static void main(String args[]) throws IOException
{
a = new int[20];

for (int i = 0; i < 20; i++)
{
a[i] = (int) System.in.read();
System.out.print(a[i] + " ");
}
}
}

两处需要修改:
int a=new int [20]; 改为:a=new int [20];

int a[i] =(int)System.in.read(); 改为:a[i] =(int)System.in.read();

ps:要编译这个class的话,还需要写成public class

java中必须有一个主类,即用public修饰,改为public class nb 。