0
Java explain me the code
import java.util.Scanner; public class Pattern6 { public static void main(String[] args) { // Create a new Scanner object Scanner scanner = new Scanner(System.in); // Get the number of rows from the user System.out.println("Enter the number of rows to print the pattern "); int rows = scanner.nextInt(); System.out.println("** Printing the pattern... **"); for (int i = 1; i <= rows; i++) { for (int j = rows; j > i; j--) { System.out.print(" "); } for (int k = 1; k <= i; k++) { System.out.print(k + " "); } System.out.println(); } } }
2 Answers
0
There is nothing special in code if you know loops then u can easily understood try to write values on rough copy how values are changing u will understood vut first do dry run or use debugger
0
there is missed two end of lines, format this lines as
{ // Create a new Scanner object
Scanner scanner = new Scanner(System.in);
// Get the number of rows from the user
System.out.println("Enter the number of rows to print the pattern ");
First two loops prints indent, here is value of j instead of space char
98765432 i=1, j from 9 to 2
9876543 i=2, j from 9 to 3
987654
98765
9876
987
98
9