Simple Math Doubt (I hope....)

Hello
I was wondering if anyone knows how to make a variable always positive, regardless of any values added or subtracted to it....
like this:
int a = 10;
int b = 5;
int c = b-a;
i want c to be positive......
appreciate the help,
Thank you

GMX750 wrote:
int a = 10;
int b = 5;
int c = b-a;
i want c to be positive......How would you do it by hand? (Hint: Absolute value?)
Check out the Math API: [http://java.sun.com/javase/6/docs/api/java/lang/Math.html|http://java.sun.com/javase/6/docs/api/java/lang/Math.html]

Similar Messages

  • Creating a form with a field that contains a simple math problem.

    I am creating a form in Acrobat 9 Standard that contains a field that requires a simple math function (divide).
    if (QuantityRow1 > 0)
    ExtensionRow1 / QuantityRow1
    Take the value input in ExtensionRow1 and divide it by the value in QuantityRow1. I have included an IF statement to prevent an error that occur if QuantityRow1 were equal to zero.
    After inputting the data into the two fields I tab past the field where I expect to see my result and the field remains blank. I don't receive any error messages.
    Any ideas? Thanks - jb

    This is a duplicate of your question on Acrobatusers.com (
    http://answers.acrobatusers.com/Need-simple-math-operation-function-Acrobat-9-Standard-cre ating-form-q142800.aspx
    Did the information provided there not help you with your problem?
    Karl Heinz Kremer
    PDF Acrobatics Without a Net
    PDF Software Development, Training and More...
    [email protected]
    http://www.khkonsulting.com

  • A simple / silly doubt for Gail

    Hi Gail,
    I was going through the Creator Field Guide book. On page 120 you have described about adding event handler for the Resest button. There are two lines of code for setting the two textfields to empty strings. My question is do we really need to do this. The button type can be set to Reset and it does the requierd work.
    I am lonely, Am I happy ? Life goes on

    Hi,
    Thank you so much. :-) I tried it myself and you are right the old values get retained even if the reset button is clicked.
    Then again a question rears its ugly head in my mind. How many times out of 100 would a person hit the submit button by mistake instead of the reset button. Secondly, if a person has hit the submit button by mistake then he is taken to the login failed or login success page. So my question is what does setting the strings to null really achieve?
    One scenario I noticed was hitting the browser's back button has the old value in the username field if it has nto been set to null. I hope my doubts are clear.
    Thank you once again for the really wonderful explanation Brad.
    I am lonely, lonely is good, hence I am good :-)

  • Simple Math Actions ( float, double... )

    Hi guys, does anybody could help me with those
    simple calculations ?
    Take a look at next code:
    public class CMainApp {
    public static void main(String[] args) {
    float f1, f2 ;
    f1 = 1.2f ;
    f2 = 3f ;
    f1 = f1 * f2 ;
    // Why returned value couldn't be
    // 3.6 ???
    System.out.println( f1 ); // PAY ATTENTION !!! : 3.6000001
    }//main
    }//CMainApp
    For some reason I got strange answers 3.6000001. It should be 3.6.
    Is there any way to deal with this problem ?
    Thanks a lot, Mark. If you could, please mail me at
    mailto:[email protected]

    JohanUP, first thanks for respond.
    But you solution dosn't serve my needs.
    // This code line will print you 4
    // but I wants my 3.6
    System.out.println( Math.round( 1.2 * 3 ) );
    Now I'm trying some tricks with NumberFormat, If I'll
    success I'll let you guys to know.

  • Simple Math in SQL Query or cfset

    Calculated fields in the DB vs <cfset>?
    It would seem simple, but:
    ACCESS DB ;>(
    CF9
    IIS
    <cfquery name="get_total" datasource="#Request.BaseDSN#">
    SELECT SUM((current_charge+penalty)-credit) AS total
    FROM moorings
    WHERE mooring_ID = #URL.mooring_ID#
    </cfquery>
    <cfdump var="#total#"> 
    Variable TOTAL is undefined?
    or
    <cfset subtotal = current_charge+penalty>
    <cfset total = subtotal-credit>
    Variable CURRENT_CHARGE is undefined?
    Missing ',", (, #'s?
    Thanks

    Run the query without using SUM to see what values are stored in the database:
    <cfquery name="get_total" datasource="#Request.BaseDSN#">
    SELECT current_charge, penalty, credit
    FROM moorings
    WHERE mooring_ID = #URL.mooring_ID#
    </cfquery>
    <cfoutput>
    charge: #get_total.current_charge#<br />
    penalty: #get_total.penalty#<br />
    credit: #get_total.credit#<br />
    </cfoutput>
    or
    <cfdump var="#get_total#">
    Also, it's a good idea to get into the habit of using cfqueryparam in your SQL queries. It helps sanitize your inputs and prevents SQL injection attacks:
    <cfquery name="get_total" datasource="#Request.BaseDSN#">
    SELECT current_charge, penalty, credit
    FROM moorings
    WHERE mooring_ID = <cfqueryparam value="#URL.mooring_ID#" cfsqltype="cf_sql_integer">
    </cfquery>

  • How can I specify simple math like in a Formula Node but on the front panel?

    If the Formula node had a "text" property, that would work for me, because I could limit my inputs and outputs to N floating-point numbers.
    LabVIEW once had such a thing but it was in an add-on math library, and I don't remember what it was called.
    Solved!
    Go to Solution.

    Thanks; that led me directly to what I was looking for. A combination of "Parse Formula String.vi" and "Eval Parsed Formula String.vi" works perfectly for me!

  • Simple little problem, I hope...

    My keyboard number pad is set so that the <./,> key imputs as a <,> this is inconvinient when I'm filling out monatary data... how do I switch it to become a <.>?
    Sorry if this is not the proper forum...

    whats your regioanl setting. If its set to a region that uses a , instead of a . for decimal, that will do it.
    Unfortunately in System settings, you can change date formats, and time formats, but not the numeric formats.
    Hope that helps even a little,
    Jason

  • Simple math calculation in numbers

    Hi I'm trying to do a simple calculation of 46.66*2 in numbers and i get a red triangle saying syntax error. Any light on this as what is wrong.

    Hi Fuija,
    Happy to help, and strangely enough, I just got a fresh cup of coffee.
    Most issues are easier to solve when enough information is presented. Keep that in mind when you have another question.
    As to using , as the decimal separator, it's not a Mac thing. That's dependent on where you live and what regional settings you've made in System Preferences. If you'd normally write ten thousand four hundred twenty-three and five hundredths like this:
    10,423.05
    Then your regional settings for numbers should show 1,234.56
    and you should use a period as the decimal separator.
    If you'd normally write that number this way:
    10.423,05
    Then your regional settings for numbers should show 1.234,56
    and you should use a comma as the decimal separator.
    Pick whichever region is set to use the same separators as you would use when writing the number with pencil on paper.
    Regards,
    Barry

  • Eval formula node vi cannot work with simple math functions

    Hi I have problem using eval formula node.
    And it produces error.
    The formula is AI0=AI0-AI6; AI1=AI1-AI6; AI2=AI2-AI6; AI3=AI3-AI6; AI4=AI4-AI6; AI5=AI5-AI6;
    Pls see the attached. I am using LV 7.1
    Pls help. Will be grateful for your help
    Clement
    Solved!
    Go to Solution.
    Attachments:
    eval_formula_test.vi ‏29 KB

    Yes, the problem are your variable names.
    Can you give us a bit of background why you want to do such a complicated and inefficient method for such a simple operation. The same could be done trivally with exactly three primitives (index array, array subset, subtract) and no purple at all.
    LabVIEW Champion . Do more with less code and in less time .

  • Simple math operation - Help needed

    Hi, i have a simple mathematical operation to do, related to
    a shooping cart, which i want to keep simple.
    I have a input text box named QT1, where customers indicate
    quantity
    I have a dymanic text box, named ST1, where i want the value
    of QT1 to be multiplied by 10$ (hence 10)
    on the release of the button. I have a NaN answer. Here is
    the code.
    on (release) {
    var qt1:Number;
    st1 = qt1 * 10;
    And then, a grand total button will add ST1 + ST2 + ST3, with
    GT the name of the grand total dymamic box:
    on (release) {
    gt = st1 + st2 + st3;
    The second part works, but the first one, with QT1 is giving
    me a Nan (not a number) answer.
    Any help appreciated.

    Problem solved. That cary Auto-kern thing....

  • Cairngorm 3 Simple Application doubt

    Either I am missing something OR there might be a good reason for the following:
    SaveContactEvent/SearchEvent etc does not extend any Event class, then why we should be calling them events. It is ambiguous and leads to a lot of confusion. These could be appended with something else, but not event.
    More about Cairngorm 3 (in general):
    There are multiple libraries such as Observer 1.8 and ObserverParsley 1.8.
    Do I need both of them to be included in my app OR one of them will fullfil my need based on some preconditions?
    Cairngorm 3 provides guidelines and various approaches to handle multiple problems, but same time it is much more confusing to get started with a simple application.
    Every lib has it's own docs, but atleast they all could be combined under an umbrella "cairngorm docs" providing a single landing page to get an access to all the different libs.
    Thanks.

    Some of our projects append them with *Message as they are really Parsley Messages not Flex events. Would you prefer that better or do you have another suggestion? Insync indented to use the Event suffix in a more logical meaning. Technically, they could also be subclassing flash.events.Event, but Parley's messaging doesn't require that.
    Can you explain in what situation that caused you confusion though? Did you try to dispatch a Parsley message via the display list?
    Regarding the Observer libraries, we should improve our documentation to make this clearer. If you read the how-to document, only the last paragraph: "Loosely Coupling Parsley Domains - Parsley Extension" describes an extention that lives within ObserverParsley and therefore requires Parsley. The rest of the Observer library is framework independent and contains all the other components described.
    Have you seen the Introduction paragraph in Guidelines? Those explain the core concepts. Many of the libraries are optional so we don't want to imply users "have" to use all of them. The libraries section is the single entry point for all libraries.

  • Simple Math equation in Flash BUGGSSS

    I'm doing a simple Minus equation
    here it is:
    Question : 100.24 - 100.23
    My Answer : 0.01
    Flash Answer : = 0.0.00999999999999091
    Question : 10.24 - 10.23
    My Answer : 0.01
    Flash Answer : = 0.00999999999999979
    Question : 0.24 - 0.23
    My Answer : 0.01
    Flash Answer : = 0.01
    Why when i'm over 10.00, Flash gives me a wrong answer. Also,
    there is somethings weird. If I put the number in textfields and I
    display the result, it will be different of the same equation in a
    trace.
    I need to build a form that calculate money. It's a problem
    for me if decimal are not valid!
    Any idea?

    That's a common problem when calculating with decimals, not
    only in Flash. There were some good explanations in this forum, but
    it seems I can't come up with the right search terms atm... In
    short, there are always some rounding operations when calculating
    with decimals, resulting in those strange results. You can try to
    search the forum, or read
    http://en.wikipedia.org/wiki/Floating_point,
    if you want to know more about it.
    A way to avoid this is to convert the decimals into full
    numbers first, calculate, and then convert back to decimals. E.g.,
    if you always have 2 decimal parts, multiply by 100 to get full
    numbers, do the calculation, then divide the result by 100 to move
    the decimal point back in place.
    hth,
    blemmo

  • Simple math and a variable in an mc instance name

    i have several movie clips with instance names in the format
    of screened1, screened2, screened3, and so on. i am trying to
    reference a movie clip as shown below, but it's not working. what
    am i doing wrong? how do i fix it?
    this.screened[numOfItems-8].transform.matrix = F1toP0;
    the transform, matrix and all of that works fine. but when i
    add the information between [ ] to make reference to the movie clip
    instance name, no go. numOfItems is a number, and when run trace on
    it.... it does return a value in the output.

    right on. my favorite flash genius. thanks again!

  • Simple JFrame Doubt

    Why is the jextfield on the jframe so small.
    Also How do I update the textField of MyButton JFrame from JButtonActionListener?
    import java.awt.FlowLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    public class MYButton extends JFrame {
         JButton jbnButton1;
         JTextField jtfClick;
         MYButton() {
              jbnButton1 = new JButton("Click Me");
              jbnButton1.addActionListener(new JButtonActionListener(MYButton.this));
              jtfClick = new JTextField();
              setLayout(new FlowLayout());
              getContentPane().add(jbnButton1);
              getContentPane().add(jtfClick);
              setSize(400, 400);
              pack();
              setTitle("Example JFrame");
              setVisible(true);
         public static void main(String args[]) {
              new MYButton();
         public JTextField getJtfClick() {
              return jtfClick;
         public void setJtfClick(JTextField jtfClick) {
              this.jtfClick = jtfClick;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    public class JButtonActionListener implements ActionListener {
         JFrame parent;
         public JButtonActionListener(JFrame p) {
              parent = p;
         public void actionPerformed(ActionEvent e) {
    //How do I update the textField of MyButton JFrame from here
    }

    hemanthjava wrote:
    Why is the jextfield on the jframe so small. Because it hasn't been given a preferred size and FlowLayout isn't going to assign it one. Why not initialize it like:
            jtfClick = new JTextField(12);
    Also How do I update the textField of MyButton JFrame from JButtonActionListener?You could pass a reference to the JFrame to the action listener by way of the listener's constructor.

  • Calculated Column with simple math for price comparisons

    Hi all,
    I want to calculate a price difference from today's price versus the price of 5 days ago.
    Please help me with a best practice for that. Is the use of calculated column in a calculation view the right approach? How can the price field of 5 days ago be addressed? Ideally 5 should be a constant which should be able to be changed to 6 or 7 for further simulations.
    Thanks for any help.
    Guenther

    Hi Patter ,
    For the above requirement we don't need a calculation view to be created. Check the code below, I am re creating the scenario with an INNER JOIN.
      CREATE COLUMN TABLE "METALS_ONE_GEN"."TEST_TAB" (ID INTEGER,DATES DATE,PRICE INTEGER);
      INSERT INTO "METALS_ONE_GEN"."TEST_TAB" VALUES ( 1 , '2014-03-10',50);
        INSERT INTO "METALS_ONE_GEN"."TEST_TAB" VALUES ( 1 , '2014-03-15',50);
        INSERT INTO "METALS_ONE_GEN"."TEST_TAB" VALUES ( 1 , '2014-03-25',100);
        INSERT INTO "METALS_ONE_GEN"."TEST_TAB" VALUES ( 1 , '2014-03-20',80);
        INSERT INTO "METALS_ONE_GEN"."TEST_TAB" VALUES ( 1 , '2014-03-30',75);
        INSERT INTO "METALS_ONE_GEN"."TEST_TAB" VALUES ( 1 , '2014-04-04',150);
        INSERT INTO "METALS_ONE_GEN"."TEST_TAB" VALUES ( 1 , '2014-04-9',450);
    select A.DATES,
           A.PRICE,
          ( B.PRICE - A.PRICE )
           from "METALS_ONE_GEN"."TEST_TAB" A
           INNER JOIN "METALS_ONE_GEN"."TEST_TAB" B
           ON
        B.DATES = ADD_DAYS(A."DATES",5) ;
    Looks like, the JOIN operation is more optimized than the Calculation view in this case . Depends on the data , JOIN type may very .
    Sreehari
    Message was edited by: Sreehari V Pillai

Maybe you are looking for

  • Can't see forms anymore in adobe reader for iPad.

    Until the update I was able to read this form. Can anyone see why I can't any more? uwo.ca/fhs/kin/ug/programs/guides/honors_bsc.pdf

  • PROBLEM WITH FINAL CUT 4 ON INTEL MAC

    tried to install final cut version 4 on an intel macbook pro and it comes up with error message saying AGP card missing. How come my version 3 will run? Any ideas?

  • Can't install or uninstall Elements 12

    I tried installing Elements 12 from a CD on my E drive (with anti-virus off).  Went well for a while until it got to the point of installing the common items (or something like that).  I tried the "advisor" but it found nothing.  I got a message to r

  • The ibook author doesn't support Arabic well

    I tried ibook author to writer a littel book in my language (Arabic). it doesn't support Arabic well, and some time it remove some letters from the pargraph !! what's problome ? and how can I fix it ?

  • PE51 Rules

    Friends, I have created two rules Z1 & Z2 in PE51 transaction for renumeration statement form for USA, there is a conversion form Z1 & Z2 which gets called through the enhancement implemenation in RPCEDTU0. Problem is only Z2 conversion form is calle