64 763
Assignments Done
99,3%
Successfully Done
In September 2018

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.
Expert's answer
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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions