-
Java (
http://www.daniweb.com/forums/forum9.html)
| c++ prog | Nov 17th, 2008 10:45 am | |
| Need an algorithm hi, we have a simple program here that states like this:
input >= 10
ex: 12
1 Square Sqrt Cube Fouthroot
2 - - - -
3 - - - -
4
5
6
7
8
9
10
11
12
i made the code already but I still can't find a solution the solutions from 1 to 11.. my code only displays the results for the 12... I know this can be solved pretty easily by some loops, but for a strange reason,I can't find the right algorithm! lol! i just need an algorithm and just leave the programming to me..tnx |
| dickersonka | Nov 17th, 2008 11:00 am | |
| Re: Need an algorithm post your code, its hard to see what you are having trouble with |
| c++ prog | Nov 17th, 2008 11:04 am | |
| Re: Need an algorithm /*
*/
package alejo_a1;
import java.util.Scanner;
public class java {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double n;
Scanner input = new Scanner(System.in);
System.out.print("Enter integer to be solved: ");
n = input.nextDouble();
//for (double i=0; i >= 10; i++)
//if (n >= 10)
//{
//{
// for(int i = 1; i >=10; i++)
//{
// i = n;
System.out.println("The Square of " + n + "= " + Square(n));
System.out.println("The Square Root of " + n + "= " + SquareRoot(n));
System.out.println("The Cube of " + n + "= " + Cube(n));
System.out.println("The Fourth Root of " + n + "= " + FourthRoot(n));
//}
//}
//}
}
static double Square( double Squ)
{
double result = 0;
int i =0;
result= Math.pow(Squ,2);
// for (;i >= 10; i++)
return result;
}
static double SquareRoot( double TwoRoot)
{
int i =0;
double result2 = 0;
result2 = Math.pow(TwoRoot, (1/2));
while(i >= 10)
{
System.out.println("Square Root of" + TwoRoot + "= " + result2);
i++;
}
return result2;
}
static double Cube( double CubeX)
{
int i =0;
double result3 = 0;
result3 = Math.pow(CubeX, 3);
do{
//System.out.println("Cube of" + CubeX + "= " + result3);
}while(i >= 10);
return result3;
}
static double FourthRoot( double Fourth)
{
int i = 0;
double result4 =0;
result4 = Math.pow(Fourth, 0.25);
for (; i >= 10; i++)
{
System.out.println(" Fourth Root of" + Fourth + "= " + result4);
}
return result4;
}
}
it's a bit messy |
| dickersonka | Nov 17th, 2008 11:12 am | |
| Re: Need an algorithm you have your for loop commented out
for startes make these changes
int n;
n=input.nextInt();
for(int i=0; i<= n; i++){
//do your println's here using i instead of n
//if you need a double from an int use
(double)i;
} |
| All times are GMT -4. The time now is 1:56 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC