[Super-Challenge]
WAP in Java to create the following star pattern.
* * *
* * *
* * *
* * *
* * * * * * * * *
* * *
* * *
* * *
* * *
>> Do Not Spam. Do not get greedy of points.
>> Answer honestly. Do not copy others answer.
>> if the pattern in the question is not clear, kindly check the attachment
>> Good Luck!!!
Answers
Solution:
The given code is written in Java.
public class Super_Challenge_2{
public static void main(String args[]){
int i,j,c=9;
for(i=1;i<=9;i++,c--){
for(j=1;j<=9;j++){
if(i==5 ||j==5|| i==j || j==c)
System.out.print("* ");
else
System.out.print(" ");
}
System.out.println();
}
}
}
Here, I have assumed that the number of rows is fixed.
Then, I have added some conditions. If the condition is true, stars are displayed and if the condition is false, two spaces are added.
After displaying each row, a new line is added.
See the attachment for output.
•••♪
Answer:
import java.util.Scanner;
public class Edureka
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of rows: ");
int rows = sc.nextInt();
for (int i= 1; i<= rows ; i++)
{
for (int j=i; j <rows ;j++)
{
System.out.print(" ");
}
for (int k=1; k<=i;k++) { System.out.print("*"); } System.out.println(""); } for (int i=rows; i>=1; i--)
{
for(int j=i; j<=rows;j++)
{
System.out.print(" ");
}
for(int k=1; k<i ;k++)
{
System.out.print("*");
}
System.out.println("");
}
sc.close();
}
}
Explanation:
Mark me as a brainliest plz