Results 1 to 4 of 4
  1. #1
    s0meb0dy is offline Member
    Join Date
    Sep 2010
    Posts
    42
    Rep Power
    0

    Default My program has a logical error but i cant find problem

    Java 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...

  2. #2
    s0meb0dy is offline Member
    Join Date
    Sep 2010
    Posts
    42
    Rep Power
    0

    Default

    i think it has something to do with the if statements

  3. #3
    s0meb0dy is offline Member
    Join Date
    Sep 2010
    Posts
    42
    Rep Power
    0

    Default

    I found my error, i forget to reset the Base Variable

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    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.

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2011, 10:48 PM
  2. I need help with an error! Cannot find symbol error!
    By ambria1975 in forum New To Java
    Replies: 2
    Last Post: 07-07-2010, 02:37 AM
  3. Some Logical problem
    By MuslimCoder in forum New To Java
    Replies: 4
    Last Post: 03-01-2010, 09:12 AM
  4. Replies: 1
    Last Post: 07-03-2009, 09:41 PM
  5. Logical JDBC problem
    By nick2price in forum Advanced Java
    Replies: 3
    Last Post: 10-03-2008, 12:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •