Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been

Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a for loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j.

Soultion 1 is wrong.

for (j = 0; j < n; j++)

{ System.out.print("*"); }

Solution 2 is wrong

for(j=1;j<=n;++j) { System.out.print("*"); }

I tried both of these and nothing works. Please provide the screenshot of the output also. thanks

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions