0
is there any better way??
Write a Java program to form a staircase shape of n coins where every k-th row must have exactly k coins my program- import java.util.Scanner; public class Stair_case { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int count=0; if (n>0) { int i; for(i = 1; i<=n; i++) { if (n < i) { break; } n = n - i; count++; } } System.out.println("Number of rows: "+ count); } } OUTPUT ; 16 Number of rows: 5
1 Answer
+ 1
Are you sure it's the code? I don't see the coins in output ...