+ 1
Why there is no output for this code I want to make pattern like this
**** *** ** * import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner (System.in); int input = sc.nextInt(); for (int i=input ;i<=1;--i){ for (int j =1; j <= input ; ++j){ System.out.print("* "); } System.out.println(); } } }
7 Respuestas
+ 2
Hey Shivam Rawal, here is the corrected code :))
for (int i = input; i>= 0; i--) {
for (int j = 0; j < i; j++) {
System.out.print("* ");
}
System.out.println();
}
In the first for loop, 'i' is deceasing every time and we are running the second loop 'i'th times, so the output looks like :
****
***
**
*
When the input is 4!
+ 3
I did it
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int input = sc.nextInt();
for (int i=1 ;i<=input ;++i){
for (int j =1; j <= ( input - i+1) ; ++j){
System.out.print("* ");
}
System.out.println();
}
}
}
+ 1
i=input, for ex: 4
i<=1 is false , it shloud be i>=1
+ 1
tysm I didn't noticed
+ 1
you need to check like j<=i instead of j<=input..
So replace this
for (int j =1; j <= i ; ++j)
You're changing decreasing i value not input value so.
0
Y it is printing
*****
*****
***** and not
****
***
**
*
- 1
for(int i=input; i>=1; i--)
And all other code is correct