Results 1 to 5 of 5
  1. #1
    bollbudb is offline Member
    Join Date
    Aug 2015
    Posts
    1
    Rep Power
    0

    Default 74 year old novice needs help

    Java Code:
    import java.math.BigInteger;
    import java.util.Scanner;
    public class abc;
    {
                   public static void main (String[] args)
                   {
                         /*  big integer declarations */
                         BigInteger i1, i2, i3;
                         i1 = new BigInteger (“111222333444555”);
                         i2 = new BigInteger (“111000111000222”);
                         /*  Boolean declarations */
                         Boolean boo1 = true,  boo2 = false;
                         /* addition */
                          i3  =  i1.add(i2);
                          String myStr  =  “Result of addition is “  +i3;
                          System.out.println(myStr);
                          /* subtraction */
                           i3  =  i1.subtract(i2);
                           String myStr1 = “Result of subtraction is “  +i3;
                           System.out.println(myStrl);
                           /* is equal to */
                           if (i1.equals(i2))
                           {
                        String myStr2 =  i1+”equals BigInteger”+i2”is”+bool;
                        System.out.println(myStr2);
                            }
                            else
                            {
                             String myStr2 =  i1+”equals BigInteger”+i2+”is”+boo2;
                             System.out.println(myStr2);
                             }
                             /*  is not equal to  */
                             if(!i1.equals(i2))
                             {
                              String myStr2 =  i1+”not equals BigInteger”+i2+”is”+boo1;
                              System.out.println(myStr2);
                              }
                              else
                              {
                               String myStr2 =  i1+”not equals BigInteger”+i2+”is”+boo2;
                               System.out.println(myStr2);
                                }
                                /*  compareTo method is used to find greater than/less than values */
                                int b3 = i1.compareTo(i2);
                                String s1 = i1+ “ values is equal to “ +i2;
                                String s2 = i1+ “ is greater than “ +i2;
                                String s3 = i2+ “ is greater than “ +i1;
                                if( b3 == 0 )
                                            System.out.println( s1 );
                                else if( b3 == 1 )
                                             System.out.println( s2 );
                                 
                                else if( b3 == -1 )
                                             System.out.println( s3 );
                           }
                    }
    Last edited by JosAH; 08-25-2015 at 08:07 AM. Reason: aded [code] ... [/code] tags

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: 74 year old novice needs help

    Please go through Forum Rules, with particular reference to the third paragraph. Then check out BB Code List - Java Programming Forum - Learn Java Programming and edit your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: 74 year old novice needs help

    Also, you posted a wall of code but neglected to ask a question.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,422
    Blog Entries
    7
    Rep Power
    28

    Default Re: 74 year old novice needs help

    I added code tags for you, but the forum software ruined it again (it can't handle comments very well); but more important is: what is your question? From the code I can see that you wan to experiment with BigIntegers, but doesn't it work? Doesn't it compile?

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  5. #5
    Join Date
    Aug 2015
    Location
    Northern California
    Posts
    31
    Rep Power
    0

    Default Re: 74 year old novice needs help

    First problem is those are not quotation marks you need to specifically use "
    Since I don't know what you are trying to do I can not help you with your code very well. I usually do not post the answers inside a working piece of code because it is bad teaching. But at your age I think you are doing really well so I added comments to any errors I thought you may have made. Please have a look at what I changed.

    1. Quotes were incorrect symbol I did not add comments for every quotation mark I changed.. (Use find/replace typically found under Edit menu to change them quickly)
    2. Look for my comments on the remaining items I changed, for example the first one is /** Removed ; after class name */ ////EDIT////
    Java Code:
    package teach;
    
    import java.math.BigInteger;
    import java.util.Scanner;
    /** Removed ; after class name */ ////EDIT////
    public class abc
    {
        public static void main (String[] args)
        {
            /*  big integer declarations */
            BigInteger i1, i2, i3;
            i1 = new BigInteger ("111222333444555");
            i2 = new BigInteger ("111000111000222");
            /*  Boolean declarations */
            Boolean boo1 = true,  boo2 = false;
            /* addition */
            i3  =  i1.add(i2);
            String myStr  =  "Result of addition is "  +i3;
            System.out.println(myStr);
            /* subtraction */
            i3  =  i1.subtract(i2);
            String myStr1 = "Result of subtraction is "  +i3;
     
            System.out.println(myStr1);
            /* is equal to */
            if (i1.equals(i2))
            {
                /** Added a + after i2 variable */ ////EDIT////
                String myStr2 =  i1+"equals BigInteger" +i2 +" is" +boo1;
                System.out.println(myStr2);
            }
            else
            {
                String myStr2 =  i1+"equals BigInteger"+i2+"is"+boo2;
                System.out.println(myStr2);
            }
            /*  is not equal to  */
            if(!i1.equals(i2))
            {
                String myStr2 =  i1+"not equals BigInteger"+i2+"is"+boo1;
                System.out.println(myStr2);
            }
            else
            {
                String myStr2 =  i1+"not equals BigInteger"+i2+"is"+boo2;
                System.out.println(myStr2);
            }
            /*  compareTo method is used to find greater than/less than values */
            int b3 = i1.compareTo(i2);
            String s1 = i1+ " values is equal to " +i2;
            String s2 = i1+ " is greater than " +i2;
            String s3 = i2+ " is greater than " +i1;
            if( b3 == 0 )
                System.out.println( s1 );
            else if( b3 == 1 )
                System.out.println( s2 );
     
            else if( b3 == -1 )
                System.out.println( s3 );
        }
    }
    By the way I think you are doing extremely well keep it up
    Last edited by devMichaelSmith; 08-25-2015 at 08:53 AM.

Similar Threads

  1. Date of first day, given the week in the year and the year...
    By Lee.J.Baxter in forum Advanced Java
    Replies: 1
    Last Post: 08-26-2009, 08:48 AM
  2. Hello to all, a java novice here, please help
    By theneed4doyen in forum Introductions
    Replies: 5
    Last Post: 07-22-2008, 05:52 PM

Tags for this Thread

Posting Permissions

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