Java乘法(在PrintStream类型中不适用于参数(String, int))



任意数字的表在System.out.println(number+";)"x +我+";="+数量*我);

(在PrintStream类型中不适用参数(String, int))

package JAVAS;
import java.util.Scanner;
public class number {
public static void main(String[] args) {
Scanner num = new Scanner(System.in);
System.out.println("Enter the number ??");
int number = num.nextInt();
int i=1;
System.out.println("the table of the following number is ");
while (i <= 10)
{
System.out.println(number+" x "+i+" = ",+number*i);
i++;
}

}
}

你的问题是你有一个额外的逗号在你的打印。然而,为了清楚地说明并向您展示更好的方法,请考虑以下内容:

public static void main(String[] args) throws IOException {
try (Scanner scanner = new Scanner(System.in)) {
System.out.println("Enter the number ??");
int number = scanner.nextInt();
System.out.println("the table of the following number is ");
String format = "%d x %d = %d";
for (int i = 1; i < 11; i++) {
System.out.println(String.format(format, number, i, number * i));
}
}
}

相关内容

最新更新