Problem 1:

Question #: Write a Java program to display the following pattern. You have to take a number that is odd number. 


Solution: 

package question01; import java.util.Scanner; public class Question01 { public static void main(String[] args) { while (true) { Scanner input = new Scanner(System.in); System.out.print("Please Enter an Odd Number : "); int Oddnum = input.nextInt(); int n = Math.abs(Oddnum); for (int row = 1; row <= n; row++) { for (int col = 1; col <= n; col++) { if ((row == col) || (row + col == n + 1) || (row == 1) || (row == n) || (col == 1) || (col == n)) { System.out.print("*"); } else { System.out.print(" "); } } System.out.println(); } } }




Previous Post Next Post