Computer Applications
Write two separate Java programs to generate the following patterns using iteration (loop) statements:
*
* #
* # *
* # * #
* # * # *
Java
Java Nested for Loops
ICSE 2015
62 Likes
Answer
public class KboatPattern
{
public static void main(String args[]) {
for (int i = 1; i <=5; i++) {
for (int j = 1; j <= i; j++) {
if (j % 2 == 0)
System.out.print("# ");
else
System.out.print("* ");
}
System.out.println();
}
}
}
Variable Description Table
Program Explanation
Output
Answered By
28 Likes
Related Questions
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)
Write a program to accept any 20 numbers and display only those numbers which are prime.
Hint: 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:
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5Write 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]