Answer to Question #67110 in Java | JSP | JSF for JM

Question #67110
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);
}
}
}

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
APPROVED BY CLIENTS