Subtraction of a positive integer of a negative integer results a positive?

Hi
I have the next problem and I haven't found the reason...
I have the next Java code:
int a = -2147483648;
int b = 2147483647;
System.out.println(a - b);
The output of this lines is "1", but I don't understand why.
Thanks

>
My main issue was that I wasn't sure of the Java process for this operation, and I thought that maybe the result
-4294967295 = FFFFFFFF00000001
could throw an exception.
>
The answer to that concern is in the Java Language Spec.
http://docs.oracle.com/javase/specs/jls/se7/jls7.pdf
See sections 4.2.1 for the value ranges (you will see your MAX and MIN 'int' values there
>
4.2.1 Integral Types and Values
The values of the integral types are integers in the following ranges:
• For byte, from -128 to 127, inclusive
• For short, from -32768 to 32767, inclusive
• For int, from -2147483648 to 2147483647, inclusive
• For long, from -9223372036854775808 to 9223372036854775807, inclusive
• For char, from '\u0000' to '\uffff' inclusive, that is, from 0 to 65535
4.2.2 Integer Operations
The Java programming language provides a number of operators that act on integral
values:
• The comparison operators, which result in a value of type boolean:
◆ The numerical comparison operators <, <=, >, and >= (§15.20.1)
◆ The numerical equality operators == and != (§15.21.1)
• The numerical operators, which result in a value of type int or long:
◆ The unary plus and minus operators + and - (§15.15.3, §15.15.4)
◆ The multiplicative operators *, /, and % (§15.17)
◆ The additive operators + and - (§15.18)
◆ The increment operator ++, both prefix (§15.15.1) and postfix (§15.14.2)
◆ The decrement operator --, both prefix (§15.15.2) and postfix (§15.14.3)
◆ The signed and unsigned shift operators <<, >>, and >>> (§15.19)
◆ The bitwise complement operator ~ (§15.15.5)
◆ The integer bitwise operators &, ^, and | (§15.22.1)
• The conditional operator ? : (§15.25)
• The cast operator (§15.16), which can convert from an integral value to a value
of any specified numeric type
• The string concatenation operator + (§15.18.1), which, when given a String
operand and an integral operand, will convert the integral operand to a String
representing its value in decimal form, and then produce a newly created String
that is the concatenation of the two strings
>
These are the two statements that apply directly to your question and concern
>
Otherwise, the operation is carried out using 32-bit precision, and the result of the
numerical operator is of type int. If either operand is not an int, it is first widened
to type int by numeric promotion.
The integer operators do not indicate overflow or underflow in any way.
>
Yours are 'integer operators' operating on 'int' values.

Similar Messages

  • Can't retrieve integer result from web services

    I'm trying to retrieve integer result from my web services.
    However, what I got always was zero without any exception caught.
    Can anyone help me?
    public function getIntegerHandler(event:ResultEvent):void {
    var anInteger: int;
    anInteger = event.result.echoInt;
    }

    SOAP response:
    <?xml version='1.0'
    encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="
    http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:getIntegerResponse
    xmlns:ns="
    http://test.com/xsd"><ns:return>2</ns:return></ns:getIntegerResponse></soapenv:Body></soap env:Envelope>

  • Negative zero result

    This may be a basic question but how come when I subtract two similar values (from different tables) I get a result of negative zero? (Ex: $50.25 - $50.25 = -$0.00) It is very annoying.
    Thanks!

    Sacara,
    This issue occurs because the digital representation of some values and the results of some computations is imperfect. For all practical purposes, the error is zero, but it's there and will be noticed by sharp-eyed users like yourself. You probably don't notice the errors in numbers that you expect to be non-zero or when you expect to see zero and the error is slightly positive.
    The problem also becomes noticeable, and is more troublesome, when two results are truly identical, but the computer's renditions of the two values are slightly different, and we test for equality. Then when the computer says they aren't the same values, we probably have an incorrect boolean result. This is when it is very important to do the rounding so that we know how similar the values have to be to be considered identical.
    Some argue that Apple should protect us from these situations through internal logic. The justification for not making adjustments internally is that we would be masking the true results, even if unavoidably inaccurate, for the sake of convenience for some users and at the expense of those who need every last bit of resolution.
    It's an ongoing discussion.
    Jerry

  • ABMA to asset with negative NBV results in zero NBV

    The depreciation area was configured to allow all values for APC, Net book value and Ordinary Depreciation.  As a result, legacy assets with depreciation key MANU and negative NBV (Accumulated depreciation and Ordinaryposted  depreciation are greater than APC) were transferred without error to the target system.  However, when posting manual depreciation to these assets, the system would automatically post a value on the 'Ordinary depreciation on Transaction' field equivalent to the negative NBV after the manual depreciation. 
    Example:
    1) Values transferred using AS91:
    APC                                 10,000
    Accumulated Depr           14,000-
    Ordinary depr posted        1,000-
    NBV                                   5,000-
    2) ABMA posted                1,000-
    Note:  System posted value of 6,000 on the 'Ord depr on Trans' field
    in effect, NBV = zero.
    Please share your experience on this area.  Thanks!

    Hi
    This will create the Proble like this,
    Your Original Cost of the Asset will be - Ve,
    Where as you will be running Monthly AFAB which will calculate depreciation for the -ve values.
    Hence ,  your P&L Account will show the Less Value of Depreciation,
    This will mislead the Profit of the Organisation which is ultimately and pricipaly against Accounting Standard and Law.
    Hence don't do this ,
    Assign point if useful
    regards
    N.Kumar

  • PowerShell - Return first negative foreach result, then continue

    Hello,
    I created a foreach object as the following, described the easy way.
    FOREACH SERVER, TRY PORT, RETURN IF THE PORT IS OPEN OR CLOSED
    Lets say it checks 100 server, and the 22nd server says CLOSED : I want it to tell me that and execute some commands
    After that, I want it to continue, and give me ALL results (all CLOSED ports on the following 78 servers)
    Any ideas?

    Let me be a bit more specific..
    I have edited it a little bit, because it contains privacy sensitive information!
    The script checks all my servers in server.txt. When all the servers respond on 3389, it does nothing
    When one or more servers respond, it will put them in the .htm and mail them to me
    There are around 100 servers in there, so it takes a long time before I actually get the message, because it will take around 10 seconds to detect if a server is not responding
    What I want: I want it to do exactly the same, except: When it first detects a server is not responding, lets say the 30th in the list, I want it to mail me INSTANTLY, because the host its running on could be offline. After it did that, I want it to
    continue checking, and gather all the remaining servers which don't respond, put them all in the htm and send it to me.
    This way I will know within seconds if a server is offline, so I can check it, and then after that I will get a mail containing ALL the servers that don't respond.
    $servers = Get-Content servers.txt
    $html = "server_status_rapport.htm"
    New-Item -ItemType file $html -Force | Out-Null
    foreach ($servers in $servers)
     $connection = New-Object net.sockets.tcpclient
     try
      $connection.Connect($servers, "3389")
      if ($connection.Connected)
       $connection.Close()
     catch [System.Management.Automation.MethodInvocationException]
      Write-Host "Offline: $servers"
      Add-Content $html "$servers <br>"
      $offline = "true"
    if ($offline -eq "true")
     $htmlresult = Get-Content server_status_rapport.htm
     $body = @"
     <font face="tahoma" size="2">
     The following servers are offline:<br><br>
     $htmlresult </font>
     $email = new-object system.net.mail.mailmessage
     $smtp = new-object system.net.mail.smtpclient
     $email.from = "SERVERMON"
     $email.to.add("emailaddress")
     $email.subject = "SERVERS OFFLINE!"
     $email.body = $body
     $email.isbodyhtml = $true
     $email.priority = [system.net.mail.mailpriority]::high
     $smtp.host = "localhost"
     $smtp.send($email)
    I could be wrong, but it appears to me that, once set as "true" in the catch block, variable $offline will continue to have that value in all subsequent iterations of the foreach loop, thereby reporting all subsequent servers tested as offline, even those
    that are not.
    I'd suggest fixing this by preceding the try statement with "$offline = "false".
    But while I am at it, I wonder why you are not using the Boolean values $true and $false, i.e.:
        $offline = $true
        if ( $offline ) {
            # as before
    Al Dunbar -- remember to 'mark or propose as answer' or 'vote as helpful' as appropriate.

  • Binary addition,subtraction and modulus...plz help urgent

    plz help me on this query...
    i need to pass two 512 bit number as string,then convert them to binary and
    then perform binary addition,subtraction,modulus operations on those two numbers.finally convert result to integer.
    i designed a code which doesnt work correct.it is:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package bytearrayopeations;
    import java.math.BigInteger;   
    * @author sheetalb
    public class binaryadding {
        public static void main(String[] args) {
            BigInteger a = new BigInteger("123456");
            BigInteger b = new BigInteger("5121");
            String bb1 = a.toString(2);
            String bb2 = b.toString(2);
            String ss1 = null;
            String ss2 = null;
            String result = "";
            String carry="0";
            System.out.println("first value=" +bb1);
            System.out.println("second value=" +bb2);
            int k=bb1.length();
            int h=bb2.length();
            System.out.println("length 1="+ k);
            System.out.println("length 2=" +h);
            int p=h-k;
            //System.out.println("difference=" +p);
            int q=k-h;
            //System.out.println("difference 2=" +q);
            if(h==k)
           else if(h>k)
                for(int i=0;i<p;i++)
                    bb1="0"+bb1;
                System.out.println("new value of first=" +bb1);   
        else if(h<k)
            for(int i=0;i<q;i++)
                bb2="0"+bb2;
            System.out.println("new value of second=" +bb2);
            StringBuffer sb1=new StringBuffer(bb1);
         StringBuffer sb2=new StringBuffer(bb2);
            bb1=sb1.reverse().toString();
         bb2=sb2.reverse().toString();
            //System.out.println("rev. buffer1=" +bb1);
            //System.out.println("rev. buffer2=" +bb2);
            for(int i=0;i<bb1.length();i++)
                ss1=bb1.substring(i,i+1);
                ss2=bb2.substring(i,i+1);
              System.out.println("value1=" + ss1 + "    " + "value2=" + ss2);
              if (ss1.equals("0") && ss2.equals("0")) 
                 if (carry.equals("0")) 
                     result+="0";
                        else
                            result+="1";
               else if (ss1.equals("1") && ss2.equals("1"))
                if (carry.equals("0")) 
                    result+="0";
              carry="1";
              else
                   result+="1";
                   carry="1";
        else if (ss1.equals("0") && ss2.equals("1"))
                     if (carry.equals("0")) 
                         result+="1";
                   carry="0";
                        else
                          result+="0";
                                    carry="1";
               else if (ss1.equals("1") && ss2.equals("0"))
                     if (carry.equals("0")) 
                        result+="1";
                        carry="0";
                   else
                                result+="0";
                                carry="1";
           System.out.println("sum=" +result + "         " + "carry" + carry);
                        result+=carry;
                        StringBuffer sb3=new StringBuffer(result);
                        result=sb3.reverse().toString();
                    System.out.println("result is " +result); 
                  System.out.println("Binary = "+ result + ", Decimal = "+Integer.parseInt(result,2));
    }plz provide me or email me if possible java coding for all three operations as soon.
    [email protected]

    One thread is enough. Continue here:[http://forums.sun.com/thread.jspa?threadID=5373720&messageID=10643157#10643157]

  • RegEx String Negation

    Hello,
    I'm trying to find a regular expression that will match any file URI in the WEB-INF/lib directory and the jars within it except a couple of specific jars, let's say a.jar and b.jar.
    For instance, I'd like the expression to match WEB-INF/lib/c.jar/myClass.class and WEB-INF/lib/d.jar/myClass.class but not any file inside and including the WEB-INF/lib/a.jar and WEB-INF/lib/b.jar
    From what I understand so far, it would be ideal if I could somehow group a literal string "a.jar" and "b.jar" into two distinct entities, E1 and E2 and use negation brackets to something of the effect WEB-INF/lib/[^E1E2].* which would match everything that begins with WEB-INF/lib except those strings directly followed by E1 and E2, a.jar and b.jar respectively.
    Is there a way to do this?

    jschell wrote:
    sabre150 wrote:
    The fact that you can use the regex class to construct code that is processed in a loop means that what I said is exactly correct.Come off it. Why are you being so defensive and pedantic? I was expressing the view that it could be done in one stage rather than in two. If you think that your procedure outlined in reply #1 results in better code than I posted in reply #6 then post something to illustrate this.
    Except that you said "There is no need for this ..."
    Meaning one does not have to use an explicit loop and accept files only when the name does not match a file to be rejected. One can use a FileFilter using a negative look ahead to do the excluding. As you point out later, one could just have well used a ! operation and saved the negative look ahead.
    >
    Which reads as though you think that your solution is in fact better in some way than what I said and/or that what I said is incorrect.I did not say or imply that your solution is incorrect. I said "There is no need for this since one can use 'negative lookahead' to exclude files from the match." with the accent being on the word 'need'. I saw your solution in reply 1 as needing an explicit loop when one is not needed. I still read it that way.
    >
    Your solution is doing nothing but exactly what I said except that you use a negative case where negating a positive one would do exactly the same thing.Not unless I am totally misunderstanding what you were saying. I saw then and still do see your solution as requiring one to get a list of the files then explicitly go though the list to create a list of those that are not in the rejected set. Your solution needs an explicit loop. Mine does not require an explicit loop.
    >
    Modifying your code (to a semi pseudo example)...
    return ! name.matches("^(a\\.jar|b\\.jar)$");Yep. I agree. But that is not what I read into reply 1. You did not mention class FileFilter. You did use the words 'file filter'. You implied an explicit loop which is not needed.
    >
    >>>
    Because you are using the regex class and doing a comparison one file name at a time it means that a positive regex (which you negate) works just as well and probably better than negative look ahead.Again, I was just removing a processing stage.
    Again which suggests that you think your solution is somehow different than what I claimed exclusive of the fact that you are using a negative case rather than negating a positive one.I just claim that your reply 1 implied an explicit loop which is not needed. If that is not what you meant then I misunderstood.
    >
    >>>
    Now if the java API has a method that takes a regex expression and filters files names then a negative look ahead would probably be ideal.I didn't say the API did have such a class. I don't see the need for RegexFileFilter to be in the API (though I have one in my private library) since as I illustrated it is trivial to implement with the current API.Just to be clear you do understand that your solution is in fact in a loop right? Yes - but the the loop is behind the scenes hidden in the listFiles() method.
    Each file individually is subjected to a regex comparison. Yes.
    The implementation of the loop itself is irrelevant and specifically not detailed for reason in my response.That is all we are arguing about. I think it is very very very relevant since reply 1 implies an explicit loop is required.
    >
    After that the only difference is
    1. Your solution uses a regex crafted to look for a negative condition
    2. My uses a regex crafted to look for a positive case and then negate the result.I agree that the regex bit makes little or no difference but the explicit loop does.
    >
    In the above how do you think that your solution is better, more complete, or substantially different than what I proposed? Do you think that a negative regex is more expressive than negating the result? Or perhaps more efficient?I never said that. I don't say that. As I keep saying - my solution does not require an explicit loop though behind the scenes there is a loop.
    >
    And finally you do understand that if the Java API itself did offer a service like this then your regex would in fact be correct because such an API would very likely assume a positive match?Which is probably why I thought in terms of negative look ahead because my RegexFileFilter does look for a positive match. I also have a NotFileFilter which chains to another file filter and returns the inverse of result of the chained FileFilter.
    In this case there is no such API and so in crafting such an API one can code it to use a negative match. That is specifically why I asked if such a Java API exists. It doesn't.Either I totally misunderstood reply 1 and you were not meaning that an explicit loop is required or I misunderstand the points you have been trying to make since reply 1. Either way it's not going to get resolved without both of us spending significant time on it and I don't think the rewards are going to be worth the effort. I will let you have the last word if you care to respond to this.

  • Cannot find Position

    Matt, your question is not clear... what are you trying to accomplish? Why are you sorting lines in the order form?
    It seems to only tell you if the top or bottom line is selected when that line is selected.

    I have created an sort function on a access from
    this code has updated 2 records at once
    1 with a number e.g. 2 and another record with the number 3
    When this code is ran it should and and subtract on the position column.
    I found this on the internet but cannot change it to my fields and get the attached error
    This topic first appeared in the Spiceworks Community

  • Integer Overflow with IMAQ ArraytoImage

    Hi all,
    I am working on a relatively basic image acquisition and display .vi. One of the goals of this .vi is to calibrate our hardware by splitting the original image into 4 quadrants. We then perform basic addition/subtraction operations between the different quadrant image arrays to ensure that they overlap cleanly. In other words, we take two different quadrants and subtract the first from the second and then display the result. This is all clear to me, and seems to be working well.
    My question has to do with the IMAQ ArraytoImage.vi. How does it handle the case where the array contains values outside the allocated space? We're using U16 Grayscale format but have the option to go to something else if necessary. Say one image has a value of 500 and we're subtracting off 600.. Is the -100 represented as a 0 or does it wrap around? Likewise how does an overflow, say 64000 + 3000 work out? I looked into changing the overflow settings in the add and subtract functions but this is only allowed for fixed point numbers.
    Thank you in advance for your help,
    Paul

    Hi phogan,
    If you have a U16 and you subtract a larger number from a smaller number, your result will be 2^16 plus the (negative) result. For instance if you have 500 - 600, the -100 would be represented as 2^16 - 100, or 65436.
    If you add two numbers that exceed the maximum value, the count will roll over. So if you have 64,000 + 3,000, the result you will see is 1464.

  • A library program for negative exponents.

    Ok im looking to create a program that can take a number and take that number to a negative exponent. such as this
    2^(-2) = .25 this is what i would like to accomplish. heres what i have.
    public static double power(double base, double expo)
    //return 0 if either is negative
    double result=1.0;
    if (expo<0.0)
    expo*=-1.0;
    for(double x=expo;x>0.0;x--)
    result=result*base;
    result=1.0/result;
    System.out.println(result);
    //compute the power function
    if(base<0.0)
    {  for(double x=expo;x>0.0;x--)
    { result=(result)*(base);
    System.out.println(result);
    else
    for(double x=expo;x>0.0;x--)
    result=result*base;
    System.out.println(result);
    //return -1 if it gets too big
    double almostToBig = 2147483647.0/base;
    if(result > almostToBig)
    return -1.0;
    return result;
    ive fooled around with the neg expo part a ton. That wasnt my best code but ive tried every combination i can think of to get it to work. Please let me know what i need to do.

    Ummm, are you going to call this program ReinventTheWheel? Because there's already a java.lang.Math.pow(double, double) method built-in.

  • Subtracting two numbers in double format gives incorrect result

    Hello,
    I have a table with two fields in Number (Field Size: Double; Decimal Places: Auto).  When using a query i try to subtract one field from the other I get incorrect results:
    Field1
    Field2
    Result
    2.60299223923846
    2.60259423701324
    3.98002225218796E-04
    0.644498511499839
    0.645908903902985
    -1.41039240314556E-03
    1.51021791504783
    1.51372591514976
    -3.50800010193808E-03
    <tfoot></tfoot>
    When I paste the above into Excel, I get the correct results:
    Field1
    Field2
    Result
    2.60299223923846
    2.60259423701324
                         0.00039800222521880
    0.64449851149984
    0.64590890390299
                       (0.00141039240314556)
    1.51021791504783
    1.51372591514976
                       (0.00350800010193808)
    Would much appriciate any help in how to get the correct values in Access Query.
    Thank you

    Field1
    Field2
    Result
    2.60299223923846
    2.60259423701324
    3.98002225218796E-04
    0.644498511499839
    0.645908903902985
    -1.41039240314556E-03
    1.51021791504783
    1.51372591514976
    -3.50800010193808E-03
    Hi Vasilii,
    In my opinion the results are correct, only they are presented in scientific notation. You can do some formatting, to display the results the way you want.
    See the Help on the use of Format.
    Imb.

  • Subtraction in Results Row

    Is there any way at all to have the results row in a query do a subtraction instead of summation?
    If not how can I get a difference between two characteristics?

    Hi Shelly,
       Subtraction of what, are you trying in the query result?
       Are you trying to calculate difference btw characteristics or key figures..
       Please make your question more clear to get good response from members..
    Regards,
    Ramesh

  • Assembler: subtracting symbols in different sections

    Hello,
    the x86(_64) assembler that comes with Sun Studio refuses to compute the difference between symbols in different sections with an error message: "Illegal subtraction - symbols from different sections".
    Even if it makes sense to refuse such subtractions (is there a standard somewhere that says they are illegal? The ELF ABI maybe?), gnu tools accept them, so people start using them (apparently there can be some benefits), and the code fails to compile with Sun Studio. I know gcc regularly has such problems since around 2005, and the latest version of gmp also has this issue.
    Is there a chance such subtractions may become legal in some not too distant future?

    The GNU assembler manual says that a program cannot subtract
    symbols from different sections. The text states
    Subtraction. If the right argument is absolute, the result has the section of
    the left argument. If both arguments are in the same section, the result is
    absolute. You may not subtract arguments from different sections.
    I wrote some trial programs that subtracted symbols from different sections.
    The assembler accepted one of them, but most failed to assemble with error
    messages such as
    t.s: Assembler messages:
    t.s:27: Error: can't resolve `a' {.data section} - `main' {.text section}
    There is a reason to reject such expressions. There is no ELF relocation type
    for such expressions.
    The one program that succeeded in assembling produced the value zero for
    the subtraction even though it should have been nonzero.
    I ran my tests under SLES 10 SP2. I used the assembler in /usr/bin/as. It is
    possible that other Linux distros would produce different results.
    Bob Corbett

  • Subtracting 2 times from each other??

    Hi
    I have 2 time which I have retrieved by using the getTime() methods associated with java.util.Date.
    How do I subtract these 2 times now, to display the difference??
    Thanks

    Hi,
    Your method calls already give you long values. Just subtract them and create a new Date using the result. For example:
    Date d1 = new Date();
    Date d2 = new Date();
    long val1 = d1.getTime();
    long val2 = d2.getTime();
    Date d3 = new Date( val2 - val1 );
    Regards,
    Manfred.

  • Variable might not have been initialized error in an assignment for school

    Hello All... I am very new to Java (started class about 2 weeks ago) and my current assignment has me a bit stumped on what I am doing wrong. I have put the code in this message for everyone to take a look at and offer advice or point me in the right direction on what I missed a step on. I appreciate any help you can offer.
    The error is coming on line 39:
    * Program: MathProgramExtra
    * Author: Michael Stewart
    * Date: August 22, 2010
    * Program Purpose: This program is intended to display selection and iterative statements.
    import javax.swing.*;
    public class MathProgramExtra
        public static void main (String[] args)
            Object[] mathPossibilities = {"+", "-", "*", "/", "%"};
            Object[] firstintegerPossibilities = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
            Object[] secondintegerPossibilities = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
            Object[] options = {"Yes, Please", "No, Thank You"};
            String m;
            String f;
            String s;
            int firstint;
            int secondint;
            int answer;
            char ans = 'Y';
            while(ans !='N')
                System.out.println("ans in beginning of loop is :"+ans);
                m = mathOp(mathPossibilities);
                f = firstNum(firstintegerPossibilities);
                s = secondNum(secondintegerPossibilities);
                firstint = firstNumConversion(f);
                secondint = secondNumConversion(s);
                performMath(m, firstint, secondint);
                add(m, firstint, secondint);
                subtract(m, firstint, secondint);
                multiply(m, firstint, secondint);
                divide(m, firstint, secondint);
                modulus(m, firstint, secondint);
                printMath(answer);
                ans = verifyAnswer(options);
                System.out.println("ans in end of loop is :"+ans);
                if (ans == 'Y')
                    continue;
                else
                    break;
            System.exit(0);
        public static String mathOp(Object[] possibilities)
            String sentence = "Please select a mathematical operation";
            String m = (String)JOptionPane.showInputDialog(null, sentence, "Operation Question",
            JOptionPane.PLAIN_MESSAGE, null, possibilities, "+");
            return m;
        public static String firstNum(Object[] possibilities)
            String sentence = "Please select an integer";
            String f = (String)JOptionPane.showInputDialog(null, sentence, "First Integer",
            JOptionPane.PLAIN_MESSAGE, null, possibilities, "0");
            return f;
        public static String secondNum(Object[] possibilities)
            String sentence = "Please select another integer";
            String s = (String)JOptionPane.showInputDialog(null, sentence, "Second Integer",
            JOptionPane.PLAIN_MESSAGE, null, possibilities, "1");
            return s;
        public static int firstNumConversion(String f)
            int firstint = 0;
            if(f.equals ("0"))
                firstint = 0;
            else if(f.equals("1"))
                firstint = 1;
            else if(f.equals("2"))
                firstint = 2;
            else if(f.equals("3"))
                firstint = 3;
            else if(f.equals("4"))
                firstint = 4;
            else if(f.equals("5"))
                firstint = 5;
            else if(f.equals("6"))
                firstint = 6;
            else if(f.equals("7"))
                firstint =7;
            else if(f.equals("8"))
                firstint = 8;
            else if(f.equals("9"))
                firstint = 9;
            else if(f.equals("10"))
                firstint = 10;
            return firstint;
        public static int secondNumConversion(String s)
            int secondint = 0;
            if(s.equals("1"))
                secondint = 1;
            else if(s.equals("2"))
                secondint = 2;
            else if(s.equals("3"))
                secondint = 3;
            else if(s.equals("4"))
                secondint = 4;
            else if(s.equals("5"))
                secondint = 5;
            else if(s.equals("6"))
                secondint = 6;
            else if(s.equals("7"))
                secondint =7;
            else if(s.equals("8"))
                secondint = 8;
            else if(s.equals("9"))
                secondint = 9;
            else if(s.equals("10"))
                secondint = 10;
            return secondint;
        public static int performMath(String m, int firstint, int secondint)
            int answer = 0;
            if (m.equals("+"))
            answer = add(m,firstint, secondint);
            if (m.equals("-"))
            answer = subtract(m,firstint, secondint);
            if (m.equals("*"))
            answer = multiply(m,firstint, secondint);
            if (m.equals ("/"))
            answer = divide(m,firstint, secondint);
            if (m.equals ("%"))
            answer = modulus(m, firstint, secondint);
            return answer;
        public static int add(String m, int firstint, int secondint)
            int answer;
            answer = (firstint + secondint);
            return answer;
        public static int subtract(String m, int firstint, int secondint)
            int answer;
            answer = (firstint - secondint);
            return answer;
        public static int multiply(String m, int firstint, int secondint)
            int answer;
            answer = (firstint * secondint);
            return answer;
        public static int divide(String m, int firstint, int secondint)
            int answer;
            answer = (firstint / secondint);
            return answer;
        public static int modulus (String m, int firstint, int secondint)
            int answer;
            answer = (firstint % secondint);
            return answer;
        public static void printMath(int answer)
            String message = "Your answer is:" + answer;
            JOptionPane.showMessageDialog(null, message, "Alert", JOptionPane.INFORMATION_MESSAGE);
        public static char verifyAnswer(Object[] options)
            char ans = 'N';
            int n = JOptionPane.showOptionDialog(null, "Would you like to enter another problem, Yes or No?", "Another Problem?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
            switch(n)
                case 0:
                    ans = 'Y'; break;
                case 1:
                    ans = 'N'; break;
            return ans;
       

    mstew1979 wrote:
    Thank you! I actually just got it working :)Cool. Here's a bit of advice, just in case you "fixed" it by making a common mistake: Don't just initialize a variable to a dummy value to make the compiler happy. Those "not initialized" errors usually point to a logic error. But just initializing the variable to 0, null, etc. at declaration, usually you're just masking the logic error so the compiler doesn't see it. You haven't fixed anything.
    public String signum (int x) {
      String result;
      if (x > 0) {
        result = "positive";
      else if (x < 0) {
        result = "negative";
      return result;
    }Here we have a compiler error, brought on by my logic error of forgetting to account for x being 0. The wrong way to fix it would be to blindly change the declaration of result to String result = ""; or == null;. The logic error is still there, but now it's hidden from the compiler. So we have an error at runtime instead--we don't get a valid response if we pass in 0. Runtime errors are much harder to debug than compile-time errors.
    The correct response to the compiler's "not initialized" error is to look at our code more carefully and see what we might have missed. In this case, we would add and else clause that returns "zero".

Maybe you are looking for

  • Contabilização de Remessa em doação

    Pessoal, Temos um item cadastrado em nosso sistema em que as contas contábeis são definidas pelo Grupo de Itens em que a conta de receita está criada como (Venda de Mercadorias - Matriz). Numa determinada operação teremos que enviar um destes produto

  • Safari on Snow Leopard doesn't play right with multimedia on WordPress

    I have a problem when I insert a QuickTime movie or Flash graphic into a WordPress post. The problem is that the CSS drop-down menu on the post page fall 'behind' the QuickTime movie instead of in front. To combat this I inserted the following embed

  • Basic questions about Tomcat

    Hi all, I'm new to Tomcat and I have a few questions... 1) I have a HttpServlet class in my server. Will an instance of this class be created for each request?. For performance reasons, can I specify a number of instances to be pre-created before use

  • Oracle e-Business Suite R12 installation

    Greetings!! I'm in the process of downloading the Oracle E-business Suite R12 software on Delivery Cloud. What I'm not so sure of is.. 1. Which Files should I download for the complete installation for practise and learning purposes, because I see a

  • Where are the group calendars stored?

    I had a server crash and have been restoring info from the old server drive. I have everything working perfectly and restored except the group calendars. thought they would just restore with the wiki. anybody know where the files are stored?