Sunday 16 August 2015

WAP in java to accept two nos m & n and to display all nos between m and n.

//Accept m and n and display nos between given range

import java.util.Scanner;

class Range {

public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter values of m and n:");
int m=sc.nextInt();
int n=sc.nextInt();

if(m==n)
System.out.println("No nos.");
else if(m>n)
{
for(int i=m;i<=n;i++)
System.out.println(i);
}
else
{
for(int i=n;i<=m;i++)
System.out.println(i);
}
}

}

No comments:

Post a Comment