User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 391,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,656 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 270 | Replies: 2 | Solved
Reply
Join Date: Jul 2008
Posts: 7
Reputation: ricss_madara is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ricss_madara ricss_madara is offline Offline
Newbie Poster

calculate squares and cube

  #1  
29 Days Ago
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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: Greece
Posts: 435
Reputation: javaAddict is on a distinguished road 
Rep Power: 1
Solved Threads: 43
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Pro in Training

Re: calculate squares and cube

  #2  
29 Days Ago
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;
I AM the 12th CYLON
Reply With Quote  
Join Date: Jul 2008
Posts: 92
Reputation: bloody_ninja is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
bloody_ninja bloody_ninja is offline Offline
Junior Poster in Training

Re: calculate squares and cube

  #3  
28 Days Ago
You can do this without Arrays as well.
Since this is solved, I will just post full code

Use buffer reader
----


  1. import java.io.*;
  2. public class Square {
  3. public static void main(String[] args){
  4.  
  5. int s=0;
  6. try{
  7. BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));
  8. System.out.println("Enter Length of a Side : ");
  9. s = Integer.parseInt(br1.readLine());
  10. double area = s*s;
  11. System.out.println("Area of Square : "+area);
  12. double volume =s*s*s ;
  13. System.out.println("Volume of Cube : "+volume);
  14. }
  15. catch(Exception e){
  16. System.out.println("Error : "+e);
  17. }
  18. }
  19. }


EDIT: /facepalm, didnt see he said no input. ARG
Last edited by bloody_ninja : 28 Days Ago at 3:44 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Java Marketplace
Thread Tools Display Modes

Other Threads in the Java Forum

All times are GMT -4. The time now is 11:05 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC