Results 1 to 7 of 7
Thread: Simple question...I hope
 01072011, 06:23 PM #1Member
 Join Date
 Jan 2011
 Posts
 12
 Rep Power
 0
Simple question...I hope
Java Code:public class Calculator2 { public static void main(String[] args){ double result = result_of("17+2811"); System.out.println(result); } public static double result_of(String equation) { if(equation.contains("+")) { //equation.split not String.split String[] split_up_equation = equation.split("[+]"); double result = 0.0; for(int i=0;i<split_up_equation.length;i++) { //add the double value result += result_of(split_up_equation[i]); } return result; } if(equation.contains("")) { String[] split_up_equation = equation.split("[]"); double result = 0.0; for(int i=0;i<split_up_equation.length;i++) { result += result_of(split_up_equation[i]); } return result; } return Double.valueOf(equation); } }
Can anyone help me
 01072011, 06:27 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,005
 Blog Entries
 7
 Rep Power
 23
 01072011, 06:28 PM #3
What happened when you tried? Keep in mind that you don't have to use the += operator; it's just a shortcut for doing something like this:
Java Code:int x = 7; x = x + 2; // same as x += 2;
Edit Too slow! But recommended reading: http://download.oracle.com/javase/tu...bolts/op1.htmlHow to Ask Questions the Smart Way
Static Void Games  GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum  Come say hello!
 01072011, 06:29 PM #4Member
 Join Date
 Jan 2011
 Posts
 12
 Rep Power
 0
so
Java Code:if(equation.contains("")) { String[] split_up_equation = equation.split("[]"); double result = 0.0; for(int i=0;i<split_up_equation.length;i++) { result = result_of(split_up_equation[i]); } return result; } return Double.valueOf(equation);
Java Code:double result = result_of("5020");
 01072011, 06:32 PM #5
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,005
 Blog Entries
 7
 Rep Power
 23
 01072011, 06:37 PM #6How to Ask Questions the Smart Way
Static Void Games  GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum  Come say hello!
 01072011, 06:40 PM #7Member
 Join Date
 Jan 2011
 Posts
 12
 Rep Power
 0
Similar Threads

very simple Question
By arsenal4ever_11 in forum NetBeansReplies: 2Last Post: 05272010, 08:51 PM 
hope to help me
By ABUALI in forum Advanced JavaReplies: 7Last Post: 05272010, 04:43 PM 
some simple question?
By jperson in forum New To JavaReplies: 4Last Post: 05032010, 05:32 PM 
hope there is an easier way.
By IYIaster in forum New To JavaReplies: 6Last Post: 10142009, 07:26 AM 
Simple Question
By barusk in forum NetworkingReplies: 13Last Post: 03042009, 08:33 PM
Bookmarks