# sum of cubes

Page 1 of 1

## 6 Replies - 9300 Views - Last Post: 05 March 2009 - 10:50 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=90806&amp;s=b6cde70d3a7a5ee44f341184fd25a50b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 custurd122000

Reputation: 2
• Posts: 182
• Joined: 05-March 09

# sum of cubes

Posted 05 March 2009 - 10:26 AM

import java.io.*;
import java.util.*;
public class lab4_2 {
public static void main(String[]args){

Scanner in=new Scanner(System.in);
System.out.println("Input n:");
double n;
n=in.nextDouble();

final double side1;
side1 = Math.pow(1,3)+Math.pow(2,3)+Math.pow(n,3);
final double side2;
side2 = Math.pow((1+2+n),2.0);

while(n>0){
if(side1 == side2)
System.out.print("The two sides are equal");

}//end while
System.out.printf("side1= %5.2f\n", side1);
System.out.printf("Side2= %5.2f\n", side2);
}//end main
}// end class

Is This A Good Question/Topic? 0

## Replies To: sum of cubes

### #2 KYA

• Wubba lubba dub dub!

Reputation: 3196
• Posts: 19,226
• Joined: 14-September 07

## Re: sum of cubes

Posted 05 March 2009 - 10:32 AM

Java does not have a System.out.printf(), it does have system.out.println()/print().

In addition, put your question in the post itself rather then the title, it gets cut off.

There's some problems with your loop:

```while(n>0){
if(side1 == side2)
System.out.print("The two sides are equal");

}//end while

```

n isn't inputted here, so this will execute infinitely as long as the initial input is greater then zero.

### #3 custurd122000

Reputation: 2
• Posts: 182
• Joined: 05-March 09

## Re: sum of cubes

Posted 05 March 2009 - 10:36 AM

thank you...

### #4 Locke

• Sarcasm Extraordinaire!

Reputation: 550
• Posts: 5,624
• Joined: 20-March 08

## Re: sum of cubes

Posted 05 March 2009 - 10:37 AM

KYA, on 5 Mar, 2009 - 11:32 AM, said:

Java does not have a System.out.printf()

...Sorry, you're wrong.

### #5 KYA

• Wubba lubba dub dub!

Reputation: 3196
• Posts: 19,226
• Joined: 14-September 07

## Re: sum of cubes

Posted 05 March 2009 - 10:39 AM

Holy shit it does. I checked the API before to be sure too, I must have missed it. I am a horrible person.

There's no need to use it in this instance though

This post has been edited by KYA: 05 March 2009 - 10:40 AM

### #6 Locke

• Sarcasm Extraordinaire!

Reputation: 550
• Posts: 5,624
• Joined: 20-March 08

## Re: sum of cubes

Posted 05 March 2009 - 10:41 AM

KYA, on 5 Mar, 2009 - 11:39 AM, said:

Holy shit it does. I checked the API before to be sure too, I must have missed it. I am a horrible person.

There's no need to use it in this instance though

You're half right...the System class does not have a printf() method...but we want too look at the out (PrintStream) object of the System class...which does have the method.

### #7 BigAnt

• May Your Swords Stay Sharp

Reputation: 102
• Posts: 2,392
• Joined: 16-August 08

## Re: sum of cubes

Posted 05 March 2009 - 10:50 AM

Yep there is a printf function,

Also to the topic creator make sure to post using code tags You can edit your post to do this.