From bfa5861a123cde757e7b22acb54de745658c9eab Mon Sep 17 00:00:00 2001 From: Zeeshan <66550180+ZeeshanK07@users.noreply.github.com> Date: Sun, 16 Oct 2022 01:40:28 +0530 Subject: [PATCH] Updated forloop.java Provided the option to print the number using the for loops in both orders as per user input --- src/forloop.java | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/forloop.java b/src/forloop.java index 0fb13a0..3022d7f 100644 --- a/src/forloop.java +++ b/src/forloop.java @@ -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); + } } } }