What I am trying to accomplish is having the user input a number (5 for example), and then printing 25, 16, 9, 4, and then 1 (squaring each number until it hits 0).
Here is the question: U9IwaIygBD.jpg
Here is my code so far:
import java.io.*; import java.util.*; public class Problem { public static void main(String args[]) { System.out.print("\nPlease enter an integer. "); Scanner b=new Scanner(System.in); int g = b.nextInt(), sum = 0, r = 0, f = g; do { sum = g * g; g*=g; System.out.println("\n" + sum); f--; sum = f * f; System.out.println("\n" + sum); } while(g<0); } }
This prints 2 squared numbers. So if I entered 5, 25 and 4 would print. Obviously I want to make it so I don't need to keep making system.out.printlns, and just have a very small block of code. If you can help that would be greatly appreciated.