javaeclipseconsoleprintfsystem.out

printf is not showing up in the console Java Eclipse 19


Every time I run my Java code on Eclipse JDK 19, the console says it's terminated but nothing shows up in there.

package rnt;

import java.util.Arrays;
public class App {

    public static void main(String[] args) {

        for(int number = 1; number < 10; number++) {
            for(int multiplier = 1; multiplier < 1; multiplier++) {
                System.out.printf("%d X %d = %d \n", number, multiplier, number * multiplier);
            }
        }   

    }
}

Image of my console

So far I tried checking the compiler in the properties of my project, and everything is running on version 19. I tried changing it to version 18 but still getting the same results.

I checked if Eclipse needs updates and as of right now, everything is updated.

I notice I tend to get errors whenever I try to use System.out.printf when I code in Java. Sometimes it works, sometimes it doesn't. I'm following along with this video it's just not working on mine.

Is there any reason why System.out.printf is like this in Java?


Solution

  • There is nothing wrong the printf statement. It's the inner for loop that's wrong. The variable multiplier is initialised as 1, and the condition is < 1.

    The loop will never run because the condition is never met. As you're printing table, correct the inner for loop to:

    for(int multiplier = 1; multiplier <= 10; multiplier++)