127k views
4 votes
Write a program in Java to display the given pattern.

1
3 5
5 7 9
7 9 11 13
9 11 13 15 17
—————————————
• kindly don't give improper or spam answers
• best of luck! :)​

1 Answer

4 votes

Answer:

class Main {

public static void main(String args[]) {

for(int i=0; i<6;i++) {

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

System.out.printf("%d ",2*i+1+2*j);

}

System.out.println();

}

}

}

Step-by-step explanation:

You will need two nested loops for sure.

For the exact assignments of variables, many flavors of the solution exist, this is just one possible option.

User Dita
by
6.3k points