WAP to take a number from the user and print 20 numbers backwards from the number taken using for loop and scanner class
Answers
Answered by
0
Answer:
Program:-
//Program using Scanner class
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int n;
System.out.println("Enter the number");
n=in.nextInt();
System.out.println("The 20 backwards numbers are:");
for(int i=1;i<=20;i++)
{
n--;
System.out.println(n);
in.close();
}
}
}
- The program is simple just run a loop and increment it for 20 iterations and decrement the entered number and print the numbers within the loop.
Attachments:
Similar questions