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(); } } }

29th Jun 2021, 12:54 PM
Abhishek Bairwa
Abhishek Bairwa - avatar
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
29th Jun 2021, 6:25 PM
💫As💫
💫As💫 - avatar
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
29th Jun 2021, 7:41 PM
zemiak