Showing posts with label java programs for practices. Show all posts
Showing posts with label java programs for practices. Show all posts

Java program for the pattern of 'B' | JAVA Patterns | JAVA POINT

 

Java codes for B

Ques : Write a Java Program for the following pattern 'B'


* * * *
* *
* *
* *
* * * *
* *
* *
* *
* * * *


PROGRAM :


import java.util.Scanner;
public class PatternB
{
public static void main(String[] args)
{
System.out.print("Enter the number of
rows : ");. // 9
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
System.out.println();
for (int i=0;i<n ;i++ )
{
for (int j=0;j<=n/2 ;j++ )
{
if (i==0 && j!=n/2 || j==0 || j==n/2 &&
i!=0 && i!=n/2 && i!=n-1 || i==n/2
&& j!=n/2 || i==n-1 && j!=n/2)
{
System.out.print("* ");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}

Java program for the pattern of 'A' | Pattern Designs | JAVA POINT

 
Java codes for A

Ques : Write a Java program for the following pattern of 'A'


* * *
* *
* *
* * * * *
* *
* *
* *


PROGRAM :



import java.util.Scanner;

public class PatternA
{
public static void main(String[] args)
{
System.out.print("Enter the number of
rows : ");. // 9
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
System.out.println();
for (int i=0;i<n ;i++ )
{
for (int j=0;j<=n/2 ;j++ )
{
if (i==0 && j!=0 && j!=n/2 || j==0 &&
i!=0 || j==n/2 && i!=0 || i==n/2)
{
System.out.print("* ");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
}
}


Also read :