Computer Applications
Write two separate Java programs to generate the following patterns using iteration (loop) statements:
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5
Java
Java Nested for Loops
ICSE 2015
32 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 1; i <=5; i++) {
for (int j = 5; j >= i; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
Variable Description Table
Program Explanation
Output
Answered By
17 Likes
Related Questions
Write a menu driven program to display all prime and non-prime numbers from 1 to 100.
Enter 1: to display all prime numbers
Enter 2: to display all non-prime numbersHint: A number is said to be prime if it is only divisible by 1 and the number itself.
Write two separate Java programs to generate the following patterns using iteration (loop) statements:
*
* #
* # *
* # * #
* # * # *Write a program to calculate and display the factorials of all the numbers between 'm' and 'n' (where m<n, m>0, n>0).
[Hint: factorial of 5 means: 5!=5*4*3*2*1]
Write a program to compute and display the sum of the following series:
S = (1 + 2) / (1 * 2) + (1 + 2 + 3) / (1 * 2 * 3) + -------- + (1 + 2 + 3 + ----- + n ) / (1 * 2 * 3 * ----- * n)