Asked by sarah
I have to write a program in java that prompts and reads the size of a table (assume the table is math square table), and plotting number and star as the following pattern in the output. For example: when reading size = 4, the table in the output should be:
***4
**34
*234
1234
so far I have this but it is not correct:
Scanner scan = new Scanner(System.in);
System.out.println("Input the size of table ");
int size = scan.nextInt();
System.out.println();
for(int row2 = 1; row2 <= size ; row2++)
{
for(int wsCount = size; wsCount < row2; wsCount--)
{
System.out.print("*");
}
for (int count2 = size-row2+1; count2 >= 1 ; count2++)
{
System.out.print(size-row2 +1);
}
}
***4
**34
*234
1234
so far I have this but it is not correct:
Scanner scan = new Scanner(System.in);
System.out.println("Input the size of table ");
int size = scan.nextInt();
System.out.println();
for(int row2 = 1; row2 <= size ; row2++)
{
for(int wsCount = size; wsCount < row2; wsCount--)
{
System.out.print("*");
}
for (int count2 = size-row2+1; count2 >= 1 ; count2++)
{
System.out.print(size-row2 +1);
}
}
Answers
There are no human answers yet.
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.