0

hey guys, im having problem converting this to a while loop.

   int lineB;
        int starB;
        for(lineB=1; lineB<=10;lineB++)
        {
            for(starB=10; starB>=lineB; starB--)
                System.out.print("*");
            System.out.println();
        }
        System.out.println();

Can it be written like this?

int lineB=1;
int starB=1;
while(lineB<=10)
{
    while(starB>=lineB)
    {
     StarB--;
     System.out.print("*");
     System.out.println(); 
     }
   lineB++;
}

Edited by Dani: Formatting fixed

10
Contributors
15
Replies
17
Views
8 Years
Discussion Span
Last Post by Ezzaral
Featured Replies
  • 1
    Ezzaral 2,714   7 Years Ago

    [QUOTE=mobmgg;1065411]convert for loop to a while loop for count= 1 to 50 display count End for[/QUOTE] [CODE]while (notPayingAttentionToTheRules) { ignore(); }[/CODE] Start a new thread if you have a question. Show some effort if you would like assistance. Read More

0

Did you test both the coding? If the result for both coding are the same, then there should not be any problem in the conversion.

0

Thanks guy i got the code to work. heres the final code!

int lineB=1;
        while(lineB<=10)
        {
            int starB=10;
            while(starB>=lineB)
            {
                starB--;
                System.out.print("*");
            }
            System.out.println();
            lineB++;
        }

Edited by Dani: Formatting fixed

0

number = 10;
sum = 0;
for (var i=1; i<= number; i++) {
sum = sum + number;
}
document.write("sum = " + sum);


number = 10;
for (var i=number; i > 0; i--) {
if ( i%2 == 1)
document.write(i);
}


product = 1;
number = 5;
for (var i=1; i < (number+1); i++) {
product = product * number;
}
document.write(product);


for ( var i=1; i<= 5; i++) {
for (var j=1; j<=3; j++) {
document.write("*");
}
document.write("<br />");
}

0

First of all this is a 11 month-old thread.
Second, do you understand why what you have written is wrong? Also the OP has already figured out his problem. You hardly made any contribution

0

int lineB=1;
int starB=1;
while(lineB<=10)
{
starB=10;
while(starB>=lineB)
{
starB--;
System.out.print("*");
System.out.println();
}
lineB++;
}
dis is the corrected code!!!!!!

0

First of all this is a 11 month-old thread.
Second, do you understand why what you have written is wrong? Also the OP has already figured out his problem. You hardly made any contribution

sry i didn't see dat it was 11 months older now
sorry ..........

0

sry i didn't see dat it was 11 months older now
sorry ..........

Also the guy was trying to cheat at an online exam. If you look at a recent post he says: "I want the solution within 30 minutes or I will fail".

Meaning that despite your good heart, you shouldn't post the solution, because this is against the forum rules. We do not give ready solutions just because someone has asked for it.
We only help those that show an effort; we don't hand in their homework.

Keep trying to help people and don't let this thread get you down

0

Also the guy was trying to cheat at an online exam. If you look at a recent post he says: "I want the solution within 30 minutes or I will fail".

Meaning that despite your good heart, you shouldn't post the solution, because this is against the forum rules. We do not give ready solutions just because someone has asked for it.
We only help those that show an effort; we don't hand in their homework.

Keep trying to help people and don't let this thread get you down

k i will take care of it in future.......

-1

<html>
<head>
<script type="text/javascript">
function inputoutput()
//assumes: document.meow.textbox.value
// results: output the number inputed by the user
{
var n;
n = document.meow.textbox.value
alert(" " + n);
}
</script>
</head>
<body>
<form name="meow">
<input type="text" name="textbox" size="10" value="" />
<br/><br/>
<input type="button" value="click here" onClick="inputoutput();" />
</form>
</body>
</html>

Votes + Comments
Disgusting how many times you need to be told to not revive old threads with lame posts.
-1

A request to the moderators please lock this thread as I doubt anything related to original post is bound to be added here anymore and for no reason at all is being brought on the first page repeatedly.

0

convert for loop to a while loop
for count= 1 to 50
display count
End for

1

convert for loop to a while loop
for count= 1 to 50
display count
End for

while (notPayingAttentionToTheRules) {
  ignore();
}

Start a new thread if you have a question. Show some effort if you would like assistance.

Edited by Ezzaral: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.