My program has a logical error but i cant find problem

• 09-26-2010, 05:16 AM
s0meb0dy
My program has a logical error but i cant find problem
Code:

```/**  * @(#)DifAnalysis.java  *  * @https://sites.google.com/site/s0m3b0dysstuff/  * @Ryan Fabela  * @version 1.00 2010/9/24  */ import java.util.*; import java.io.*; import java.lang.Math; import java.math.BigDecimal; import java.math.*; public class DifAnalysis {   public static void main(String[] Arguments){           Scanner oSciNote = new Scanner(System.in);     BigDecimal SciNoteP1,Base,Target,SciNoteP2,BaseminusTarget,Answer,BaseminusTargetpow;/* P1 Means out of 3.125 x 10^5 the 3.125 part.     P2 means the 10^5 part. target is the target exponent, for example when trying to get to kilo- you would put 10^3. base is the metric prefixes exponetial value.     answer should be self explanatory.*/     String oMetricPrefixes = "tera-, T, 10^12\ngiga-, G, 10^9\nmega-, M, 10^6\nkilo-, k, 10^3\ndeci-, d, 10^-1\ncenti-, c, 10^-2\nmilli-, m,10^-3\nmicro-, µ, 10^-6\nnano-, n, 10^-9\npico-, p, 10^-12\nFor base units use 10^0";     String oErrorMes;         System.out.println(oMetricPrefixes);     System.out.println();     System.out.println("Instruction:\nWhen it asks you for the digit term use the first set of numbers, for example in 3.125 x 10^5 you would put 3.125.\nWhen it asks for the exponential term put the last set of numbers, for  exapmle you would put 5.\nWhen it asks for the base exponential value you would put the metric scientific notaion of the metric prefix, for example, when going from micrograms to kilograms you would put -6(refer to above chart)\nWhen it asks for the target exponential value you would use one of the above metric scientific notations, for example when trying to get to kilo- you would put 3./nMakesure to only put numbers and decimal points.  No commas!");         System.out.println();     System.out.println("Please put enter the digit term:");     SciNoteP1 = new BigDecimal(oSciNote.nextLine());         System.out.println("Please enter the exponential term:");         SciNoteP2 = new BigDecimal(oSciNote.nextLine());         System.out.println("Please enter the base exponential value:");         Base = new BigDecimal(oSciNote.nextLine());         System.out.println("Please enter the target exponential value:");         Target = new BigDecimal(oSciNote.nextLine());         Base = Base.subtract(Target);         Base = Base.abs();         if(Base.compareTo(Target)>0){                 Answer = SciNoteP1.multiply(Base);                 System.out.println(Answer);         }         if(Base.compareTo(Target)<0){                 Answer = SciNoteP1.divide(Base);                 System.out.println("The answer is: "+Answer);         }   } }```
i keep getting zero. It's supposed to solve differential Analysis problems but its not working...
• 09-26-2010, 05:18 AM
s0meb0dy
i think it has something to do with the if statements
• 09-26-2010, 05:23 AM
s0meb0dy
I found my error, i forget to reset the Base Variable
• 09-26-2010, 06:29 AM
Zack
Thanks for sharing your solution. You can also select "Mark thread solved" from the Tools menu at the top of the thread to show others that it has been solved.