0

how to write application that calculate squares and cube of the number from 0 to 10 and output in table. the program does not require any input from user?

3
Contributors
2
Replies
8
Views
8 Years
Discussion Span
Last Post by bloody_ninja
0

Two arrays length 10. In one you will put the squares and at the other the cubes.
Use a for loop from 0 to 10. Calculate inside the loop theresults and put them in the array:

square[i] = i*i;
cube[i] = i*i*i;
0

You can do this without Arrays as well.
Since this is solved, I will just post full code

Use buffer reader
----

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

	    int s=0;
	           try{
	        BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
	        System.out.println("Enter Length of a Side  : ");
	        s = Integer.parseInt(br1.readLine());
	        double area = s*s;
	        System.out.println("Area of Square : "+area);
	        double  volume =s*s*s ;
	        System.out.println("Volume of Cube : "+volume);
	      }
	      catch(Exception e){
	        System.out.println("Error : "+e);
	      }        
	  }
	}

EDIT: /facepalm, didnt see he said no input. ARG

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.