write a program to display the following pattern:
A
AC
ACE
ACEG
ACEGI
Answers
Example
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
Answer
import java.util.Scanner;
public class MainClass
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
//Taking rows value from the user
System.out.println("How many rows you want in this pattern?");
int rows = sc.nextInt();
System.out.println("Here is your pattern....!!!");
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= i; j++)
{
System.out.print(j+" ");
}
System.out.println();
}
//Close the resources
sc.close();
}
}
Answer:
ASSUME:
1
13
135
1357
13579
no. of rows: 5
Explanation:
class Nloop
{
void main()
{
int i,j;
for(i=1 ; i<=5 ; i++)
{
for(j=1 ; j<=I ; j=j+2)
{
System.out.print((char)(j+64));
}
System.out.println();
}
}
}