Why doesn't my program print anything? [closed]


Why doesn't my program print anything? [closed]



I am trying to make a simple Cube class and make use of StringBuilder. When I run my driver class, TestCube, nothing prints. I thought the new Cube object I created passed the integer value of '7' into the formal parameters of the Cube constructor?


Cube


StringBuilder


TestCube


Cube


Cube



Shouldn't the print statement I have print the current state of my new object (which would be 7 raised to the third power)?


package chp5;

public class Cube {

private int num1;

public Cube (int num)
{
this.num1 = (int) Math.pow (num, 3);
}


public int getnum1()
{
return num1;
}

public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("That value raised to the third power is: " + num1);
return builder.toString();
}

}


package chp5;

public class TestCube {

public static void main(String args)
{
Cube testNum = new Cube(7);

System.out.println(testNum);
}
}



This question appears to be off-topic. The users who voted to close gave this specific reason:





ideone.com/f1ixTk
– Sotirios Delimanolis
Jul 3 at 3:58





it will print 343. I also executed and verified the same. What is the output you are getting
– akshaya pandey
Jul 3 at 4:05





isn't it printing anything at all. I don't see anything wrong with the program
– Sagar Kharab
Jul 3 at 4:06





Possible duplicate of No output from Java method or of No output in console. There are more similar, use your search engine. Please search before posting a question here.
– Ole V.V.
Jul 3 at 5:09





Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages