| | |
Need an algorithm
![]() |
hi, we have a simple program here that states like this:
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
Java Syntax (Toggle Plain Text)
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
•
•
Join Date: Aug 2008
Posts: 1,158
Reputation:
Solved Threads: 136
post your code, its hard to see what you are having trouble with
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
Java Syntax (Toggle Plain Text)
/* */ 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
•
•
Join Date: Aug 2008
Posts: 1,158
Reputation:
Solved Threads: 136
you have your for loop commented out
for startes make these changes
for startes make these changes
Java Syntax (Toggle Plain Text)
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; }
Last edited by dickersonka; Nov 17th, 2008 at 11:13 am.
Custom Application & Software Development
www.houseshark.net
www.houseshark.net
![]() |
Similar Threads
- Help with LR parser algorithm (Java)
- round robin algorithm (Computer Science)
- Round Robin Algorithm Simulation (C++)
- Eigenface Algorithm (Computer Science)
- Algorithm for checking contiguous blocks (C)
Other Threads in the Java Forum
- Previous Thread: how can i measure ftp server load with request from my personal
- Next Thread: struct in programming while coding SMTP
| Thread Tools | Search this Thread |
911 actionlistener addball addressbook android applet application apps array automation binary bluetooth businessintelligence button card character class client code collision component consumer crashcourse css csv database desktop eclipse ee error fractal free ftp game givemetehcodez graphics gui html image integration j2me japplet java javaarraylist javac javadoc javaee javafx javaprojects jni jpanel julia jvm linked linux loan mac method migrate mobile netbeans objects online oriented phone physics printf problem program programming project projects radio recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server service set sms software sort sql swing test textfield textfields threads time tree trolltech ubuntu update utility windows






