Computer Science, asked by nandawakte66611, 1 year ago

wap to print this pattern in JAVA
13579
35791
57913
79135
91357

Answers

Answered by wtegwr
22

Answer:

Explanation:

import java.util.Scanner;

 

public class Pattern {

   public static void main(String[] args) {

       Scanner scanner = new Scanner(System.in);

       System.out.print("Enter n: ");

       int n = scanner.nextInt();

       for (int i = 1; i <= n; i++) {

           int num = 2 * i - 1;

           for (int j = 1; j <= n - i + 1; j++) {

               System.out.print(num + " ");

               num = num + 2;

           }

           int num2 = 1;

           for (int j = 1; j <= i - 1; j++) {

               System.out.print(num2 + " ");

               num2 = num2 + 2;

           }

           System.out.println();

       }

   }

}

Similar questions