Create a Program that will ask the user to enter a number n then display n3, (n+1)3,( n+2)3,… 5 times. Use any of the loop statement to implement the program.
import java.util.Scanner;
public class Main {
/** Number of iterations. */
private static final int COUNT = 5;
public static void main(String [] a) {
System.out.print("Please enter integer 'n' and press enter: ");
Scanner in = new Scanner(System.in);
// Can add exception handling.
int number = in.nextInt();
for (int i = 0; i < COUNT; i++) {
int result = (number + i) * 3;
System.out.println("(n + " + i + ") * 3 = " + result);
}
}
}
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!
Learn more about our help with Assignments:
JavaJSPJSF