简体   繁体   中英

No output being shown on the screen

Please see why there is being no output shown on the screen! I am writing a program that could print "Happy Birthday" 10 times on the screen. My program is:

import java.io.*;
public class Task_1
{
    public static void main(String args[])
    {
        int a;
        for(a=1;a>=10;a++)
            System.out.println("Happy Birthday");
    }
}

for(a=1;a>=10;a++) is wrong

it must be

for(a=1;a<=10;a++)

Your condition is not valid that is why you get nothing printed

import java.io.*;

public class Task_1
{
    public static void main(String args[])
    {
        for (int a = 0; a < 10; a++)
            System.out.println("Happy Birthday"); // It'll be printed 10 times
    }
}

This should work, try it out.

Your for loop was saying: if a is equal to or bigger than 10 then print "Happy Birthday" which was returning false thus not printing anything and ending the loop.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM