Answer to Question #267197 in Java | JSP | JSF for jayvee

Question #267197
  1. Using a do...while() loop, continuously scan for random integers that will be inputted by the user and print out its square, separated in each line.
  2. Once the inputted value is 0, it will still print out its square value but should then terminate the loop afterwards. Use this concept in making your loop condition.
1
Expert's answer
2021-11-16T18:30:53-0500
import java.util.Scanner;
public class Sol {
  public static void main(String[] arg) {
    Scanner s = new Scanner(System.in);
    int i = 0; 
    while ( true ) {
      int j = s.nextInt();
      if (i != j)
        System.in.println(i*i);
      else {
        System.in.println(i*i);
        break;
      }
    }
  }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS