|
-
Oct 18th, 2010, 04:56 PM
#1
Thread Starter
New Member
Square/cube root
How do I allow a user to input a number and then make them select the number 1 to cube or number 2 to square it and produce the result? I don't want to use the math function but rather something like this to square it:
result = var * 2;
System.out.println(result);
Any help in starting would be appreciated
-
Oct 21st, 2010, 09:32 AM
#2
Re: Square/cube root
Hi tracy22... Welcome to the forums...
This is an untested code for finding the squares and cubes:
java Code:
public class myJavaProgram {
public static void main(String[] args) {
//read the number from the user and store it in variables. Here, I have hardcoded the values
int num1 = 2;
int num2 = 100;
//calculating the Sqaure and Cube
int ResultSquare=num1*num1;
int ResultCube=num2*num2*num2;
System.out.println("Square :" + ResultSquare);
System.out.println("Cube :" + ResultSquare);
}
}
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Oct 21st, 2010, 09:38 AM
#3
Re: Square/cube root
Ah! You are asking for square root and cube roots ? I think, I read the question wrongly. 
Then try these links:
- http://www.homeschoolmath.net/teachi...-why-works.php
- http://www.homeschoolmath.net/teachi...-algorithm.php
...
If my post was helpful to you, then express your gratitude using Rate this Post. 
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Dec 17th, 2010, 04:12 AM
#4
Lively Member
Re: Square/cube root
Here you go mate.
and
ex.
Code:
public class apples {
public static void main(String args[]){
System.out.println(Math.sqrt(100));
}
}
Which would print out 10.0
On the off chance that I helped you ( Rate This Post){
Also If your problem was resolved;
}
-
Jan 17th, 2011, 11:37 PM
#5
Lively Member
Re: Square/cube root
Just realized you were not asking for the root. lol
On the off chance that I helped you ( Rate This Post){
Also If your problem was resolved;
}
-
Feb 2nd, 2011, 05:49 PM
#6
Hyperactive Member
Re: Square/cube root
Since you were explicitly not asking for the Math functions ...
I guess you might be looking for an operator, in which case I have to disappoint you. Java has no power operator as is available in other languages, such as in C#.
____________________________________________
Please rate my messages. Thank you!
____________________________________________
Bram Vandenbon
http://www.bramvandenbon.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|