Main.java:3: error: class Demo1 is public, should be declared in a file named Demo1.java public class Demo1{ ^ 1 error
其解决方案为 Java的类名必须为 Main
源代码:
import java.util.Scanner;
public class Demo1{
public static void main(String[] args) {
int a, i = 0;
Scanner sc = new Scanner(System.in);
a= sc.nextInt();
int b[]= new int[3];
while (a != 0) {
b[i++] = a % 10;
a = a / 10;
}
for (int k = 0; k < b[2]; k++)
System.out.print("B");
for (int k = 0; k < b[1]; k++)
System.out.print("S");
for (int k = 0; k < b[0]; k++)
System.out.print(k+1);
}
}
更改后:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
int a, i = 0;
Scanner sc = new Scanner(System.in);
a= sc.nextInt();
int b[]= new int[3];
while (a != 0) {
b[i++] = a % 10;
a = a / 10;
}
for (int k = 0; k < b[2]; k++)
System.out.print("B");
for (int k = 0; k < b[1]; k++)
System.out.print("S");
for (int k = 0; k < b[0]; k++)
System.out.print(k+1);
}
}
成功编译运行。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)