a small java program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blazedaces
    Contributor
    • May 2007
    • 284

    #16
    Originally posted by TRScheel
    Its pseudo code, and for n < 2 (or... n = 1 in an array starting at 1) then you just eliminate the final portion asking for n - 1 and just XOR the two values, AKA just do the first portion of the giant bool statement
    I would work it out... but it's a lot of typing out of 0's and 1's... so let me just ask you, does it work for floating point arithmetic?

    -blazed

    Comment

    • TRScheel
      Recognized Expert Contributor
      • Apr 2007
      • 638

      #17
      Originally posted by blazedaces
      I would work it out... but it's a lot of typing out of 0's and 1's... so let me just ask you, does it work for floating point arithmetic?

      -blazed
      Should, you would just have two numbers, one that directly influences the second.

      IE:

      1001 . 1101 = 9.13

      if the second half became greater than 100, you subract 100 and add 0001 to the first one as you normally would.

      EDIT: If you want more precision, the value you wait to subract from increases (1000, 10000, etc)

      Comment

      • mansasa
        New Member
        • Aug 2007
        • 1

        #18
        Detail of emp are maintained as a list of string. Each string contains 3 fields separated
        by a comma in the format-" name , department , salary"
        exp.

        String empDetail[] =

        {"Jim ,Dev,3000","Rob ,Dev,10000","Jo han,Acc,1000"," Mike,Acc,100"};

        Write a program to compute and print the sum of salaries of all emp in each department like
        Dev-13000
        Acc-1100.

        Comment

        • blazedaces
          Contributor
          • May 2007
          • 284

          #19
          Originally posted by mansasa
          Detail of emp are maintained as a list of string. Each string contains 3 fields separated
          by a comma in the format-" name , department , salary"
          exp.

          String empDetail[] =

          {"Jim ,Dev,3000","Rob ,Dev,10000","Jo han,Acc,1000"," Mike,Acc,100"};

          Write a program to compute and print the sum of salaries of all emp in each department like
          Dev-13000
          Acc-1100.
          ... Why are we doing this exactly? Who are you and what is the purpose of this program? We are not supposed to do your homework for you, check the forum guidelines. If that is not the case I apologize.

          This program though is not hard at all utilizing string's .split(String delimiter) method. Look it up in java's documentation on class String.

          Good luck,
          -blazed

          Comment

          • blazedaces
            Contributor
            • May 2007
            • 284

            #20
            Originally posted by TRScheel
            Should, you would just have two numbers, one that directly influences the second.

            IE:

            1001 . 1101 = 9.13

            if the second half became greater than 100, you subract 100 and add 0001 to the first one as you normally would.

            EDIT: If you want more precision, the value you wait to subract from increases (1000, 10000, etc)
            But floating point numbers aren't stored this way, they are stored as a sign bit, exponent bits, and mantissa bits as I explained above. Are you saying that to use this method we should first convert them to a new form of storing floating point numbers which has a number of bits before a decimal and a number of bits after a decimal?

            Please correct me if I'm wrong and please excuse my ignorance since I'm new to this subject.

            Thank you,
            -blazed

            Comment

            • TRScheel
              Recognized Expert Contributor
              • Apr 2007
              • 638

              #21
              You asked how I would go about doing it without + or -, and I just gave an example of how to do it. I havent really ever looked at the bit structure of a floating point number, so I couldnt give you a good example until I researched it. The method I gave above just pretends either side of the decimel is an integer. I would imagine that a floating point number looks something like:

              Decimel location Left hand value Right hand value

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #22
                Originally posted by TRScheel
                You asked how I would go about doing it without + or -, and I just gave an example of how to do it. I havent really ever looked at the bit structure of a floating point number, so I couldnt give you a good example until I researched it. The method I gave above just pretends either side of the decimel is an integer. I would imagine that a floating point number looks something like:

                Decimel location Left hand value Right hand value
                Check the 'index' article in the Java Articles section. Near the bottom there's a
                link that reads 'What every computer scientist should know about floating point
                arithmetic'. Read it; it pays back.

                kind regards,

                Jos

                Comment

                • TRScheel
                  Recognized Expert Contributor
                  • Apr 2007
                  • 638

                  #23
                  Read it, and it still doesnt open any doors as to doing floating point arithmetic any easier.

                  Comment

                  • gaya3
                    New Member
                    • Aug 2007
                    • 184

                    #24
                    Originally posted by gowrisonia
                    sum of two varaibles without using mathematical operators.

                    Hi Gowri,
                    Following code satisfied ur requirement??

                    class Addition
                    {
                    public static void main(String args[])
                    {
                    int a=1;
                    int b=5;
                    while(b>=0)
                    {
                    int c=a++;
                    System.out.prin tln("value:"+c) ;
                    b--;

                    }
                    }
                    }


                    -Thanks,
                    Hamsa

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #25
                      Originally posted by gaya3
                      Hi Gowri,
                      Following code satisfied ur requirement??

                      class Addition
                      {
                      public static void main(String args[])
                      {
                      int a=1;
                      int b=5;
                      while(b>=0)
                      {
                      int c=a++;
                      System.out.prin tln("value:"+c) ;
                      b--;

                      }
                      }
                      }


                      -Thanks,
                      Hamsa
                      1.) Please use code tags when posting code.
                      2.) That code is hopelessly wrong. Please desist from posting misinformation.

                      Comment

                      Working...