javaintegernumbersprintln

Java multiplication (in the type PrintStream is not applicable for the arguments (String, int))


Table of a any number getting this error - on System.out.println(number+" x "+i+" = ",+number*i);

(in the type PrintStream is not applicable for the arguments (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++;
}
        
    }
}

Solution

  • Your problem is you have an extra comma in your println. However, for clarity and to expose to you better methods of doing this, consider the following:

    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));
            }
        }
    }