Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Monday, 15 September 2014

Write a program Java for loop example to print stars in console

Java for loop example to print stars in console

class Stars {
  public static void main(String[] args) {
    int row, numberOfStars;

    for (row = 1; row <= 10; row++) {
      for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
        System.out.print("*");
      }
      System.out.println(); // Go to next line
    }
  }
}

O/P:

Java for loop example program output

Write a program Java for loop

Java for Loop

class ForLoop {
  public static void main(String[] args) {
    int c;

    for (c = 1; c <= 10; c++) {
      System.out.println(c);
    }
  }
}



O/P:

Java for loop example program output

Write a Java hello world program

Hello world program

class HelloWorld
{
   public static void main(String args[])
   {
      System.out.println("Hello World");
   }
}


O/P:


Java hello world code output