# Need a different way to add Cubed numbers 1-10

• February 12th, 2014, 12:53 PM
Dtank123456
Need a different way to add Cubed numbers 1-10
Code :

```/* * Put your documentation header here. */ import java.util.Scanner;   public class Lab5{   /** * Returns an integer whose value is a^3 (a cubed). * @param any integer to be cubed * @return a^3 (a cubed) */ public static int cubed(int a){ int cube = a * a * a; return cube; }   /* Answer the following questions about the method cube: *1) What is the method's return type? Integer   *2) What is the method's formal parameter name? A *3) What is the cube method's signature? int a *4) What line of code invokes the cube method? Return Cube *5) What is the name of the argument passed to cube? */ //Cubed   public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Enter an integer"); int x = in.nextInt();   // invoking the cubed method System.out.println("The cubed value of "+ x + " is " + Lab5.cubed(x)+".");   /* Below this comment, write a piece of code that will sum the cubes * 0f all the numbers from 1 to 10 inclusive. 0utput this sum (labelled). */ int a = 1; int b = 2*2*2; int c = 3*3*3; int d = 4*4*4; int e = 5*5*5; int f = 6*6*6; int g = 7*7*7; int h = 8*8*8; int i = 9*9*9; int j = 10*10*10;   System.out.println("Sum of Cubed Numbers of 1-10: "+a + b + c + d + e + f + g + h + i + j); }   } /* * Copy and paste your program output here */```

The last part with int a-j......
Is there a better way of doing this, like possibly putting into a loop and showing output from maybe a single piece of information? I hope im asking this question right.....

--- Update ---

Or really is there a better way of adding them up.... to reduce coding
• February 12th, 2014, 01:32 PM
GregBrannon
Re: Need a different way to add Cubed numbers 1-10
Yes, there is a better way. Try your loop idea and see what happens.

Why do most of your answers to questions 1 - 5 have incorrect capitalization?
• February 12th, 2014, 02:02 PM
Dtank123456
Re: Need a different way to add Cubed numbers 1-10
capitalization doesn't really matter... just answering the question.

ummm.... as far as the loop goes,

I'm not very keen on the loop idea but I'll do a little more reading and find out.