Wap to use Loops in Java

 import java.util.Scanner;


  class Loops

  {

  public static void main(String[] arg)

  {   

  Scanner scanner= new Scanner(System.in);

  int i;

  System.out.print("Enter the Range upto:");

  int n = scanner.nextInt();

  

  System.out.println("This is a for loop:");

  for(i=0; i<=n; i++)

  {

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

  }

  System.out.println(" ");

  

  System.out.println("This is a While loop:");

  i=n;

  while(i!=0)

  {

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

  i--;

  }

  System.out.println(" ");

  

  System.out.println("This is a Do While Loop:");

  i=0;

  do

  {

  System.out.println(i+"\t");

  i=i+2;

  }

  while(i<=n);

  }

  }

  

  

Comments

Popular posts from this blog

Wap to Use Increment And Decrement Operator In Java

Q. Wap to sort an array using Bubble Sort

Completed Certification from J.P. Morgan - Software Engineering Job Simulation