I am using Java in Eclipse. We have only learned for , while, and do loops so fa
ID: 645192 • Letter: I
Question
I am using Java in Eclipse. We have only learned for , while, and do loops so far. First clear working code gets points!
2. Write a loop that runs at most 10 times. Inside the loop you will print out the number of asterisks according to Which iteration of the loop you are on (so if you are on the third iteration, you will print out ***). Each iteration you will ask lithe user wants to keep going, if they say N then you will quit the entire loop without printing the asterisks for that iteration. Use break to quit the loop. I am using Java in Eclipse. We have only learned for , while, and do loops so far. First clear working code gets points!Explanation / Answer
import java.io.*;
class p
{
public static void main(String args[]) throws IOException
{
int i=1,a, j=1;
String ans="Y";
DataInputStream o = new DataInputStream(System.in);
while(ans=="Y")
{
while(i<=10)
{
while(j<=i)
{
System.out.print("*");
j=j+1;
}
System.out.print(" Do you want to keep going?");
ans=o.readLine();
if(ans.equals("N"))
{
System.out.println("Okay Goodbye");
return;
}
i=i+1;
j=1;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.