The program below is the answer to Deitel’s Java How to Program (9th Edition) Chapter 2 Exercise 2.31.
Question: Using only the programming techniques you learned in this chapter, write an application that calculates the squares and cubes of the numbers from 0 to 10 and prints the resulting values in table format, as shown below. [Note: This program does not require any input from the user.]
1 2 |
/**<br /> *<br /> * @Author: Aghatise Osazuwa<br /> * Website: www.cscprogrammingtutorials.com<br /> *<br /> * Exercise 2.31 - Table Of Squares And Cubes<br /> * This Program Calculates And Prints A Table Of Squares And Cubes Of The Numbers From 0 to * 10<br /> *<br /> */ <br /><br /><br />public class Ex02_31 {<br /> public static void main (String [] args) {<br /><br /> System.out.println ("Number Square Cube");<br /> System.out.printf ("%d %d %dn", 0, (0 * 0), (0 * 0 * 0));<br /> System.out.printf ("%d %d %dn", 1, (1 * 1), (1 * 1 * 1));<br /> System.out.printf ("%d %d %dn", 2, (2 * 2), (2 * 2 * 2));<br /> System.out.printf ("%d %d %dn", 3, (3 * 3), (3 * 3 * 3));<br /> System.out.printf ("%d %d %dn", 4, (4 * 4), (4 * 4 * 4));<br /> System.out.printf ("%d %d %dn", 5, (5 * 5), (5 * 5 * 5));<br /> System.out.printf ("%d %d %dn", 6, (6 * 6), (6 * 6 * 6));<br /> System.out.printf ("%d %d %dn", 7, (7 * 7), (7 * 7 * 7));<br /> System.out.printf ("%d %d %dn", 8, (8 * 8), (8 * 8 * 8));<br /> System.out.printf ("%d %d %dn", 9, (9 * 9), (9 * 9 * 9));<br /> System.out.printf ("%d %d %dn", 10, (10 * 10), (10 * 10 * 10));<br /> }<br />}<br /> |
3 Comments
how can i do this exact problem but with a while loop in it?
in simple form.
@Alex-Kun Yes, you can but the question states that "only programming techniques learnt in the chapter(chapter 2) of the book" should be used.
ehm you can do this exercise with one line of code, this stuff it's too much