Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/forloop.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
class abc {
import java.util.Scanner;

public class Main {
// Provided the userinput option so that numbers can be printed in both orders

public static void main(String[] args)
{
for (int i = 1; i <= 10; i++) {
System.out.println(i);
System.out.println("Press 1 if you want to print the number in ascending order"); // Asked user input for their choice
Scanner S1=new Scanner(System.in);
int input=S1.nextInt();//taking user input

if(input==1)//selecting as per the userinput
{
for (int i = 1; i <= 10; i++) {
System.out.println(i);
}
}
else
{
for (int j = 10; j >= 0; j--) {
System.out.println(j);
}
}
}
}