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.
1
Expert's answer
2017-04-04T01:44:07-0400
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); } } }
Comments
Leave a comment