当前位置: 首页 > 知识库问答 >
问题:

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

何志业
2023-03-14

在系统上获取此错误的任意数字的表。出来println(数字“x”i“=”,数字*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++;
}
        
    }
}

共有2个答案

郭凯
2023-03-14

使用系统。出来println(数字“x”i“=”数字*i)

庄嘉
2023-03-14

你的问题是你的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));
        }
    }
}
 类似资料: