Java 乘法(PrintStream 类型不适用于参数 (String, int))
Java multiplication (in the type PrintStream is not applicable for the arguments (String, int))
任意数的Table
收到此错误 - 在 System.out.println(number+" x "+i+" = ",+number*i);
(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++;
}
}
}
你的问题是你的 println 中多了一个逗号。但是,为了清楚起见并向您展示执行此操作的更好方法,请考虑以下内容:
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));
}
}
}
Table 收到此错误 - 在 System.out.println(number+" x "+i+" = ",+number*i);
(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++;
}
}
}
你的问题是你的 println 中多了一个逗号。但是,为了清楚起见并向您展示执行此操作的更好方法,请考虑以下内容:
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));
}
}
}