InterviewSolution
Saved Bookmarks
| 1. |
Write a program in java of pattern 1 31 531 7531 97531 |
|
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 currentNum = 2 * i - 1; for (int J = 1; j <= i; j++) { System.out.print(currentNum + " "); currentNum = currentNum - 2; } System.out.println(); } } } Here is a sample output. Enter n: 5 1 3 1 5 3 1 7 5 3 1 9 7 5 3 1 |
|