Simple Java Program to print 1 to 100?

i need a simple java basic program to print counting from 1 to 100 in rows of 10 in each row ...please help!!

2 Answers

Relevance
  • 9 years ago
    Favorite Answer

    Here is some code that does that generically for any range of integers:

    int col=1;

    public static void output(int min,int max)

    {

    if(min==max)

    {

    System.out.print(""+min+" ");

    col=col<<1;

    if(col>=0x400)

    {

    System.out.print("\n");

    col=1;

    }

    return;

    }

    int mid=min+((max-min)/2);

    output(min,mid);

    output(mid+1,max);

    }

    Of course, you should only hand this in as homework if you're willing to explain to your teacher why you decided to use recursion and bitwise shifts rather than iteration. Otherwise...well, why not do your own homework for a change? Who knows, you might actually learn something!

  • Anonymous
    9 years ago

    Hi,

    Please find the program below:

    public static void main(String[] args) {

    for (int i = 1; i<=100;i++)

    {

    System.out.print(i + " ");

    if(i%10==0)

    {

    System.out.println();

    }

    }

    }

    If you like the program, please give rating to my answer. Thank you.

    Source(s): Personal Experience.
Still have questions? Get your answers by asking now.