Monday, May 24, 2010

How do i write a program using java that uses the length of the side of a cube?

the surface area of a cube can be known if we know the lenght of an edge. i need to write a program that takes the length of an edge (an integer) as input and prints the cubes surface area as the output.

How do i write a program using java that uses the length of the side of a cube?
import java.io.*;


class Cube


{


public static void main(String args[]) throws IOException


{


BufferedReader br=new BufferedReader(new InputStreamReader(System.in));


System.out.print("Enter the edge of the cube ");


String a=br.readLine();


int e=Integer.parseInt(a);


int SA=6*e*e;


System.out.print("The total surface area of the cube is "+SA);


}


}
Reply:import java.util.Scanner;


public class Cube{


public static void main(String[] args){


int length;


Scanner scan = new Scanner(System.in);


System.out.println("What's the length of the cube edge%26gt;");


length = scan.nextInt();


System.out.println("The surface area is " + (length*length)*6);


}


}
Reply:L * W





its the same as a 2d square.





3d is an illusion, so if its "rotated", it just has a different appearence.

tomato plants

No comments:

Post a Comment