SUM Parenthesis - Difference???

Hi;
i just want to ask if there is any differences between calculating summuation inside the pharenthesis or not???
Example Query;
select     a12.CATEGORY,
     (sum(a11.COL1) / (CASE WHEN COL2=0 THEN NULL ELSE COL2 END)) SUM1,
     sum((a11.COL1 / (CASE WHEN COL2=0 THEN NULL ELSE COL2 END))) SUM2
from     table1     a11,
     table2a12
where     a11.ID = a12.ID
group by     a12.CATEGORY
Which one is faster? SUM1 or SUM2 or no difference???
Note that DB is Oracle 10g.
Thanks...

It makes no difference because the query won't work anyway. COL1 is aggregated but COL2 isn't...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select 4 as col1, 2 as col2 from dual union all
  2             select 5, 3 from dual union all
  3             select 6, 0 from dual union all
  4             select 7, 3 from dual)
  5  --
  6  select sum(col1) / (case when col2=0 then null else col2 end) as sum1
  7        ,sum(col1 / case when col2=0 then null else col2 end) as sum2
  8* from t
SQL> /
select sum(col1) / (case when col2=0 then null else col2 end) as sum1
ERROR at line 6:
ORA-00937: not a single-group group function

Similar Messages

  • How to Calculate Sum of Difference between two dates

    Hi,
    I'm using BI Publisher in Siebel CRM.
    In RTF template I have the following expression to calculate the Difference between dates
    <?xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-MM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE)?>
    The above expression works for me to calculate the dates.
    I need to calculate the Sum of all these dates for a Group.
    Want to know the Syntax for Sum function using Date_diff.
    Tried the following and didn't work.
    <?Sum(xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-aMM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE))?>
    Not sure what I'm doing wrong here...
    Anyone please help...
    Thanks
    PV

    Hi
    To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
    select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
    trunc( sysdate-created ) "Dy",
    trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
    trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
    trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
    to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
    sysdate-created "Tdy",
    (sysdate-created)*24 "Thr",
    (sysdate-created)*24*60 "Tmi",
    (sysdate-created)*24*60*60 "Tsec"
    from all_users
    where rownum < 50
    HTH
    RangaReddy

  • Difference between columns

    Hi all,
    I have a situation like the one pointed out in the picture here: http://i40.tinypic.com/dlq5tz.jpg
    This is a pivot table, and it extracts the Products and their average on the shelf on the last month and the same period one year ago.
    I would like to have a column that gives me an indicator (could be a sum or difference) in order to understand if the current month value is greater than the previous one; in this way, I could set a conditional formatting rule that displays an "up arrow" or "down arrow" depending of the trend.
    Thanks for the help!
    Best regards,
    Alberto

    Hai Alberto,
    click on the compound layout and select the mesurable value from the "rows" section and left click on the more options and then you can find the new calculated item and then select it. If you are intrested to calculate then you can do that there. These are done at the pivot view.
    coming to the Table view - Filter using, it is also very easy using the filter option in the edit formula button in the creteria field, when clicking the edit formula, click on the filter option.
    Follow the link below for more clarification of the using filters:
    http://download.oracle.com/docs/cd/E12096_01/books/AnyUser/formulaeditor.html
    Hope it will helpful you....
    Thanks,
    Mani.
    Edited by: ManiEswar on 13-May-2010 12:39

  • Difference in Minutes

    I want to calculate minutes between these 2 rows:
    My input data looks like:
    id cola colb colc cold
    123 12/14/2004 7:15:00 AM 12/14/2004 5:00:00 PM 12/14/2004 7:15:00 AM 12/14/2004 5:00:00 AM
    123 12/14/2004 12:30:00 AM 12/14/2004 5:00:00 PM null null
    Output looks like:
    id cola colb cole colc cold colg
    123 12/14/2004 7:15:00 AM 12/14/2004 5:00:00 PM 855 12/14/2004 7:15:00 AM 12/14/2004 5:00:00 AM 585
    cole --> sum of difference of minutes between colb and cola from row 1 & 2
    colg ---> difference in minutes between cold and colc
    Thanks in advance

    alter session set nls_date_format = 'MM/DD/YYYY HH:MI:SS PM'
    with t as (
               select 123 id,to_date('12/14/2004 7:15:00 AM') cola,to_date('12/14/2004 5:00:00 PM') colb,to_date('12/14/2004 7:15:00 AM') colc,to_date('12/14/2004 5:00:00 AM') cold from dual union all
               select 123,to_date('12/14/2004 12:30:00 AM'),to_date('12/14/2004 5:00:00 PM'),to_date(null),to_date(null) from dual
    select  id,
            cola,
            colb,
            trunc((colb - cola) * 24 *60) cole,
            colc,
            cold,
            trunc((cold - colc) * 24 *60) colg
      from  t
            ID COLA                   COLB                         COLE COLC                   COLD                         COLG
           123 12/14/2004 07:15:00 AM 12/14/2004 05:00:00 PM        585 12/14/2004 07:15:00 AM 12/14/2004 05:00:00 AM       -135
           123 12/14/2004 12:30:00 AM 12/14/2004 05:00:00 PM        990
    SQL> SY.

  • Passing values to seperate methods

    How do you pass integer values to different methods called in a program. Example: methods sum() and difference(). User has to enter two numbers. The program must print the numbers, calculate the sum and the difference, and then print the answers. I created a method that figured both the sum and difference with the use of the if / else procedure. I tried to create two seperate methods but could not get the second method to read and calculate the two numbers input. Below is what I ended up with.
    import java.util.*;
    Author:     Galen Rogers
    Date:          09 July 06
    Subject:     COM 209 Wk 3 Homework problem # 2.
    Program to create "Sum & Difference" method.
    public class NumbersCalc
         public static void sum()
              Scanner keyboard = new Scanner(System.in);
              int n1, n2, sum, diff;
              n1 = keyboard.nextInt();
              n2 = keyboard.nextInt();
              sum = n1 + n2;
              System.out.println("The sum of your numbers is: " + sum);
              if (n1 > n2)
                   diff = n1 - n2;
              else
                   diff = n2 - n1;
              System.out.println("The difference of your numbers is: " + diff);     
    Main Program:
    import java.util.*;
    Author:     Galen Rogers
    Date:          09 July 06
    Subject:     COM 209 Wk 3 Homework problem # 2.
    Program to add and subtract numbers entered by user and display answers.
    public class Numbers
         public static void main(String[] args)
              Scanner keyboard = new Scanner(System.in);
              System.out.println("Please think of two whole numbers that you want calculated.");
              System.out.println("Please enter two whole numbers and press Enter after each number.");
              NumbersCalc.sum();
    If any body can help I will really appreciate it.

    Don't do input (or even output) inside the sum() or difference() methods. Instead get the input first, store the input into two variables and then call the two methods using the stored input. Make sure those methods return the calculated values and then print those values.
    Your sum() method should look something like this:public int sum(int a, int b) {
      // just calculate result and return it
    }Same for the difference() method.

  • Aggregate in SELECT query

    Hi All,
       Is it possible to manipulate(add, subtract,...) two fields belonging to two different tables in a SELECT query or JOIN statement.
       Ex. 
           SELECT
             <TABLE1>~<FIELD1>
             <TABLE1>~<FIELD2>
             <TABLE2>~<FIELD1>
             <TABLE1>~<FIELD2>
           INTO TABLE
             <RESULT_TAB>
           FROM
              <TABLE1>
            INNER JOIN
              <TABLE2>
            ON
              <TABLE1>~<FIELD1> = <TABLE2>~<FIELD1>  ...
      My problem is, while selecting can i add or subtract two fields say <TABLE1><FIELD1> and <TABLE2><FIELD1>.
    Regards,
    Mustajab.

    Hi Mustajab!
    IMHO you can't manipulate two fields during the select (in open SQL).
    If you are interested in sums (or differences) over all entries, then you can use the aggregation function SUM and make the final calculation with the total of the columns - but not line by line.
    Regards,
    Christian

  • Scalar distance across columns

    I need to calculate the scalar (Euclidean) distance between two vectors, each dimension represented by columns in a table. I have a procedure that does it the slow and painful way: loop over all vector pairs/loop over all columns/look up the individual cell values/sum over all the differences. It appears to me though, that there should be a more straightforward way to do this using the:
    SELECT * FROM TST INTO vREF_DATA WHERE REGNO=1;
    SELECT * FROM TST INTO vCMP_DATA WHERE REGNO=2;
    syntax in PL/SQL, then loop over the variables/column elements to sum the differences. However, I can't figure out how to keep the pointers for each variable in sync.
    E.g.: coord1(1,2,3), coord2(2,3,1), differences(1,1,2), sum=4.
    I can do this in Perl using hashes/arrays, but not in PL/SQL. What is the right frame/syntax to do this? If it were a couple of hundred rows, I'd do it in Perl, but with millions of rows and hundreds of columns, it gets real tedious, not to mention easily out-of-sync with the database contents.
    I'd appreciate any suggestions!

    Michiel:
    Glad that it works for you. So, you want a fishing lesson :-).
    First, the full documentation for the DBMS_SQL package can be found here .
    Essentially, DBMS_SQL is an industrial strength version of EXECUTE IMMEDIATE (well, properly, EXECUTE IMMEDIATE is a highly simplified version of DBMS_SQL, since DBMS_SQL came first). It has many advantages over EXECUTE IMMEDIATE because it allows you full control over virtually everything to do with the query. So, you can relatively easily create bind variables on the fly to create statements with an unknown number of binds. It also allows you to find the columns from any arbitrary query through DBMS_SQL.Describe_Columns.
    You never actually see any values returned, because I never actually return any. Since you wanted your output in another table, I decided to build one big insert statement, rather than iterate through all the rows, calculate the distance, and then insert one row at a time. It seemed more efficient to me. I also decided to "hard code", through a bind variable, each of the column values from the ref_id, rather than try to dynamically build a join, which seemd simpler to me.
    1. DBMS_SQL.Describe_Columns returns a table of records, one record for each column, that gives information much like that in the xxx_tab_columns views. If some id columns may be numeric, you can test the col_type field in the table of records and put a dummy VARCHAR variable into the character columns. Just be aware that the col_type field returns a numeric version of the column_type, not a string. If you look at the text from user_tab_cols:
    SELECT text
    FROM dba_views
    WHERE view_name = 'USER_TAB_COLS'You can see where Oracle DECODES the numeric type to the NUMBER, VARCHAR2 etc. Essentially, NUMBER is 1 and VARCHAR2 is 2.
    2. I replaced the FOR scale_rec IN ... LOOP block with another DBMS_SQL built query to pull the AVG and VARIANCE from the table, it is commented in the code below.
    3. You cannot really put a threshold on the computation of the distance, since the distance is not really known to the query until it is fully executed (i.e. at the time of inserting). However, you could modify the insert query to filter values with distances greater than 3. I will leave that modification as a exercise for the fiherman, but the end sql statement would look something like:
    INSERT INTO diag
    SELECT src, id, dist
    FROM (SELECT :src_id src, id,
            SQRT(ABS((POWER((:sc2 - :mean2)/:var2, 2) - POWER((col1 - :mean2)/:var2, 2))+
                     (POWER((:sc3 - :mean3)/:var3, 2) - POWER((col2 - :mean3)/:var3, 2))+
                     (POWER((:sc4 - :mean4)/:var4, 2) - POWER((col3 - :mean4)/:var4, 2)))) dist
          FROM t
          WHERE id <> :src_id)
    WHERE dist <= 3Now here is a heavily commented version taking into account the proper formula.
    CREATE or replace PROCEDURE euclidean_distance (p_src_tab IN VARCHAR2) AS
       -- Associative Array for scaling factors
       TYPE scale_cols_tp IS TABLE OF NUMBER INDEX BY VARCHAR2(30);
       mean_cols scale_cols_tp; -- Will hold average of columns
       var_cols scale_cols_tp;  -- Will hold variance of columns
       -- Array to hold column values for the reference id
       TYPE src_cols_tp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
       src_cols src_cols_tp;
       l_dummyn NUMBER;  -- Dummy Number for Define Column
       l_ignore NUMBER;  -- Receives rows processed from queries
       l_sqlstr VARCHAR2(32767);  -- For sql statements
       src_cur  NUMBER;  -- Reference ID Cursor handle
       src_tab  DBMS_SQL.Desc_Tab;  -- Table of Records describing passed table
       src_col_cnt NUMBER;   -- Number of columns in passed table
       ins_cur  NUMBER;  -- Insert Cursor handle
       mv_cur  NUMBER;  -- Cursor handle for Mean and Variance of table
       l_col_pos NUMBER; -- Index into src_tab
       l_res_pos NUMBER; -- Column position in mv_cur
       l_x1     VARCHAR2(10);  -- Dynamic bind variable for source column values
       l_x2     VARCHAR2(30);  -- Column name from source columns
       l_meani  VARCHAR2(10);  -- Dynamic bind variable for mean of table
       l_vari   VARCHAR2(10);  -- Dynamic bind variable for variance of table
    BEGIN
       -- Get a "handle" for a cursor, and parse the query
       src_cur := DBMS_SQL.Open_Cursor;
       DBMS_SQL.Parse(src_cur, 'SELECT * FROM '||p_src_tab||' WHERE id = :src_id',DBMS_SQL.Native);
       -- Describe the table to get number of columns, their names and their types
       DBMS_SQL.Describe_Columns(src_cur, src_col_cnt, src_tab);
       -- I now have a table of records (src_tab) showing similar info
       -- to that shown in xxx_tab_columns, one record per column
       -- and the number of columns in the table (actually the number of records
       -- in src_tab) is in src_col_cnt
       -- Define the column types for src_cur.  This just tell DBMS_SQL that
       -- the column at position i (based on the column list in the select)
       -- is of the passed data type.  It is not setting a variable to
       -- receive the column value.
       -- I am assuming all inluding ID are NUMBER.
       -- If id may be alpha can test src_tab(i).col_type to check data type
       FOR i IN 1 .. src_col_cnt LOOP
          DBMS_SQL.DEFINE_COLUMN(src_cur, i, l_dummyn);
       END LOOP;
    -- This section replaces the FOR scale_rec IN LOOP
       -- Get mean and variance for passed table
       -- Build the sql statement
       l_sqlstr := 'SELECT ';
       FOR i IN 2 .. src_col_cnt LOOP
          l_sqlstr := l_sqlstr||'AVG('||src_tab(i).col_name||'),'||
                'VARIANCE('||src_tab(i).col_name||'),';
       END LOOP;
       -- l_sqlstr is now:
       -- SELECT AVG(col1), VARIANCE(col1),AVG(col2), VARIANCE(col2),
       --        AVG(col3), VARIANCE(col3),
       -- So trim the trailing , and add FROM
       l_sqlstr := RTRIM(l_sqlstr,',');
       l_sqlstr := l_sqlstr||' FROM '||p_src_tab;
       -- Set up the cursor
       mv_cur := DBMS_SQL.OPEN_CURSOR;
       DBMS_SQL.Parse(mv_cur, l_sqlstr, DBMS_SQL.Native);
       -- Getting 2 results (AVG and VARIANCE) for each column
       -- and we know that they are all numeric
       -- but need to ignore the id column so
       FOR i In 1 .. (src_col_cnt - 1) * 2 LOOP
          DBMS_SQL.DEFINE_COLUMN(mv_cur, i, l_dummyn);
       END LOOP;
       -- Now Run the query and assign columns into associative array
       l_ignore := DBMS_SQL.EXECUTE_AND_FETCH(mv_cur);
       l_col_pos := 2;  -- start in Record 2 of src_tab
       l_res_pos := 1;  -- start in Column 1 of result set
       WHILE l_col_pos <= src_col_cnt LOOP
          DBMS_SQL.COLUMN_VALUE(mv_cur, l_res_pos, mean_cols(src_tab(l_col_pos).col_name));
          DBMS_SQL.COLUMN_VALUE(mv_cur, l_res_pos + 1, var_cols(src_tab(l_col_pos).col_name));
          l_col_pos := l_col_pos + 1;
          l_res_pos := l_res_pos + 2;
       END LOOP;
       -- I end up with two associative arrays, both indexed by column name
       -- mean_cols values are the average for each column
       -- var_cols values are the variance for each column
       -- We're done with this query so
       DBMS_SQL.Close_Cursor(mv_cur);
    -- END replacement FOR scale_rec IN LOOP
       -- Build the insert statement
       -- I took the ABSolute value of the SUM of L(i) because with
       -- my data I was getting negative values which blew the SQRT
       l_sqlstr := 'INSERT INTO diag SELECT :src_id, id, SQRT(ABS(';
       FOR i IN 2 .. src_col_cnt LOOP
          -- Dynamically create bind variables to hold "fixed" values
          -- (i.e. reference values, mean, and variance
          -- and plug the correct column names for the target columns
          l_x1 := ':sc'||i; -- For i = 2 gives :sc2
          l_x2 := src_tab(i).col_name; -- For i = 2 gives COL1
          l_meani := ':mean'||i; -- For i = 2 gives :mean2
          l_vari := ':var'||i; -- For i = 2 gives :var2
          -- Append this column formula to sql statement
          l_sqlstr := l_sqlstr ||'(POWER(('||l_x1||' - '||l_meani||
                      ')/'||l_vari||', 2) - POWER(('||l_x2||' - '||
                      l_meani||')/'||l_vari||', 2)) + ';
       END LOOP;
       -- Here, l_sqlstr is:
       -- INSERT INTO diag
       -- SELECT :src_id, id, SQRT(ABS((POWER((:sc2 - :mean2)/:var2, 2) -
       --                               POWER((col1 - :mean2)/:var2, 2))+
       --                              (POWER((:sc3 - :mean3)/:var3, 2) -
       --                               POWER((col2 - :mean3)/:var3, 2))+
       --                              (POWER((:sc4 - :mean4)/:var4, 2) -
       --                               POWER((col3 - :mean4)/:var4, 2))+
       -- so get rid of the trailing + and space
       l_sqlstr := RTRIM(l_sqlstr,'+ ');
       -- Now close the open bracket from SQRT and ABS and add FROM and WHERE
       l_sqlstr := l_sqlstr||')) FROM '||p_src_tab||' WHERE id <> :src_id';
       -- Now we have a valid insert statement so
       -- Prepare and parse the insert cursor
       ins_cur := DBMS_SQL.Open_Cursor;
       DBMS_SQL.Parse(ins_cur, l_sqlstr, DBMS_SQL.Native);
       -- bind in the mean and variance which are fixed for this set of columns
       FOR i IN 2 .. src_col_cnt LOOP
          DBMS_SQL.Bind_Variable(ins_cur,':mean'||i, mean_cols(src_tab(i).col_name));
          DBMS_SQL.Bind_Variable(ins_cur,':var'||i, var_cols(src_tab(i).col_name));
          -- for i = 2, These two calls resolve as:
          -- DBMS_SQL.Bind_Variable(ins_cur,:mean2, mean_cols(COL1));
          -- DBMS_SQL.Bind_Variable(ins_cur,:var2, var_cols(COL1));
          -- which means bind the value found in mean_cols('COL1') to
          -- the bind variable :mean2 and the value found in var_cols('COL1') to 
          -- the bind variable :var2
       END LOOP;
       -- Get the reference IDs
       FOR intrest_rec IN (SELECT ref_id FROM query) LOOP
          -- For each reference ID bind into the source query
          DBMS_SQL.Bind_Variable(src_cur,':src_id', intrest_rec.ref_id);
          -- So, here, on the first iteration, we are about to execute
          -- the statement
          -- SELECT * FROM t WHERE id = 1     
          l_ignore := DBMS_SQL.Execute_And_Fetch(src_cur);
          -- Get the column values from each source row and
          -- bind that value (e.g. 1 in my sample) to variable :src_id
          DBMS_SQL.Bind_Variable(ins_cur,':src_id', intrest_rec.ref_id);
          FOR i IN 2 .. src_col_cnt LOOP
             -- Retrieve the value of each column of the source row
             -- into the table of NUMBERS
             DBMS_SQL.COLUMN_VALUE(src_cur, i, src_cols(i));
             -- Then bind it into the insert cursor
             DBMS_SQL.Bind_Variable(ins_cur,':sc'||i, src_cols(i));
          END LOOP;
          -- execute the insert statement
          l_ignore := DBMS_SQL.EXECUTE(ins_cur);
       END LOOP;
       COMMIT;
       DBMS_SQL.Close_Cursor(src_cur);
       DBMS_SQL.Close_Cursor(ins_cur);
    END;If you still have questions, I will be around until Thursday, then back January 4.
    John

  • Board game -alternate way to draw

    Thanks for reading,
    im relatively new to game devpmt, i am making a board game similar to pool.
    the board background is a JPanel on which a fixed image is drawn .i want to make a ball moving on it.The ball's image is loaded from a file .since the image is rectangular in boundary,ball when drawn on the board,displays the rectangular boundaries around it.
    is there any way to overcome this problem,
    all the drawings of board_backround_image and ball_image takesplace when the paintComponent() of the boardpanel is called.
    Any suggestions would b great helpful.....

    If you are reading from gif or png, make the background of the source image transparent. Otherwise, color the background with some unused palette color, search through the pixels after loading, and replace those pixels with transparent ones.
    If using jpg or some other lossy compression scheme, you'll not only need to have a transparency marker, but it will not always have the same RGB to compare with. Here's a quick snippet that will covert a particular color in an image to transparent pixels. The fuzziness variable is how far the red, green, and blue channels may be to still be considered marked as transparent.
    public BufferedImage transparify(Image sourceImage, Color replaceColor, int fuzziness)
       int imageWidth = sourceImage.getWidth(null);
       int imageHeight = sourceImage.getHeight(null);
       // ensure we are using a ARGB BufferedImage
       BufferedImage returnImage = new BufferedImage(imageWidth,imageHeight, BufferedImage.TYPE_INT_ARGB);
       Graphics imageG = returnImage.getGraphics();
       imageG.drawImage(sourceImage, 0, 0, null);
       imageG.dispose();
       // extract pixel data
       int[] pixels = new int[imageWidth * imageHeight];
       returnImage.getRGB(0, 0, imageWidth, imageHeight, pixels, 0, imageWidth);
       int transRed   = replaceColor.getRed();
       int transGreen = replaceColor.getGreen();
       int transBlue  = replaceColor.getBlue();
       for (int pixIndex = 0; pixIndex < pixels.length; pixIndex++) {
          // sum the difference of this pixel with the transparency marker
          int diffRed   = transRed   - ((pixels[pixIndex] >> 16) & 0xFF);
          int diffGreen = transGreen - ((pixels[pixIndex] >> 8) & 0xFF);
          int diffBlue  = transBlue -  (pixels[pixIndex] & 0xFF);
          // if close to the marker, set pixel to transparent
          boolean closeEnough = (diffRed >= 0 ? diffRed : -diffRed) <= fuzziness &&     
                          (diffGreen >= 0 ? diffGreen : -diffGreen) <= fuzziness &&  
                          (diffBlue >= 0 ? diffBlue : -diffBlue) <= fuzziness;
          if (closeEnough) {
             pixels[pixIndex] = 0; // 0 alpha makes transparent
       returnImage.setRGB(0, 0, imageWidth, imageHeight, pixels, 0, imageWidth);
       return returnImage;
    }

  • Basic Java Program help needed urgently.

    I have posted the instructions to my project assignment on here that is due tomorrow. I have spent an extremely large amount of time trying to get the basics of programming and am having some difficulty off of the bat. Someone who has more experience with this and could walk me through the steps is what I am hoping for. Any Help however will be greatly appreciated. I am putting in a lot of effort, but I am not getting the results I need. Thank you for the consideration of assisting me with my issues. If you have any questions please feel free to ask. I would love to open up a dialogue.
    CIS 120
    Mathematical Operators
    Project-1
    Max possible pts 100
    Write a program “MathOperators” that reads two integers, displays user’s name, sum, product,
    difference, quotients and modulus of the two numbers.
    1. Create a header for your project as follows:
    * Prgrammer: Your Name (1 pt) *
    * Class: CIS 120 (1 pt) *
    * Section: (1 pt) *
    * Instructor: (1 pt) *
    * Program Name: Mathematical Operators (1 pt) *
    * Description: This java program will ask the user to enter two integers and *
    display sum, product, difference, quotients and modulus of the two numbers
    * (5 pts) *
    2. Display a friendly message e.g. Good Morning!! (2 pts)
    3. Explain your program to the user e.g. This java program can add, subtract, multiply,
    divide and calculate remainder of any two integer numbers entered by you. Let’s get
    started…. (5 pts)
    4. Prompt the user- Please enter your first name, store the value entered by user in a
    string variable name. Use input.next() instead of input.nextLine(). (8 pts)
    5. Prompt the user- name, enter first integer number , store the value entered by user in
    an integer variable num1.(5 pts)
    6. Prompt the user- name, enter second integer number , store the value entered by user in
    an integer variable num2.(5 pts)
    7. Display the numbers entered by the user as: name has entered the numbers num1and
    num2.(5 pts)
    8. Calculate sum, product, difference, quotients and modulus of the two numbers. ( 30 pts)
    9. Display sum, product, difference, quotients and modulus of the two numbers. ( 10 pts)
    10. Terminate your program with a friendly message like- Thanks for using my program,
    have a nice day!!(2 pts)

    Nice try. You have not demonstrated that you've at least TRIED to do something. No one is going to do your homework for you. Your "urgency" is yours alone.

  • Deitel, Java How To Program exercise question

    Hi, :)
    I'm new to programming and I'm using the Java How To Program Fourth Edition from Deitel and Deitel as my text. I've run into a problem with Exercise 2.16 Where I'm asked:
    "Write an application that asks the user to enter two numbers, obtains the numbers from the user and prints the sum, product, difference, and quotient of the numbers."
    From that I have written this code:
    // Exercise 2.16
    /* An application that asks the user to enter two numbers, obtains the numbers from the use and prints the sum,
    product, difference and quotient of the numbers. Using the techniques shown in Fig 2.9 */
    //Java extension packages
    import javax.swing.JOptionPane;
    public class Exercise2_16{
         //Main method
         public static void main(String args[]){
         String firstNumber, secondNumber;                          //introduce variables
         int number1, number2, sum, product, difference, quotient;          //introduce variables
         firstNumber=JOptionPane.showInputDialog("Enter first integer:");     //Create input window
         secondNumber=JOptionPane.showInputDialog("Enter second integer:");     //Create input window
         number1=Integer.parseInt(firstNumber);                         //String to integer
         number2=Integer.parseInt(secondNumber);                         //String to integer
         //perform operations
         sum = number1+number2;
         product = number1*number2;
         difference = number1-number2;
         quotient = number1/number2;
         //Display results
         JOptionPane.showMessageDialog(null, "The sum is " + sum,
         "The product is " + product, "The difference is " + difference,
         "The quotient is " + quotient, "Results", JOptionPane.INFORMATION_MESSAGE);
         //End program
         System.exit(0);
         }//End main method
    }//end class Exercise2_16
    When I compile this code I get an error and I can't figure out why. Any help is really appreciated as I'm stumped and given the simplicity of the app I'm kinda bummed it has me stuck :(.

    I substituted your line and this is the error I'm receiving now:
    F:\jdk1.3\Learning Java>javac Exercise2_16.java
    Exercise2_16.java:32: unclosed string literal
    JOptionPane.showMessageDialog(null, "The sum is " + sum + ", The product is" + product + ",
    The difference is" + difference + ", The quotient is" + quotient + ", \"Results\", JOptionPane.INFORMATION_MESSAGE);
    ^
    Exercise2_16.java:35: ')' expected
    System.exit(0);
    ^
    2 errors
    It doesn't really matter to me if there are returns but maybe for readability there should be and so I learn how to as well.

  • BOFC: Consolidated Amounts always will be splittet?

    Hi Experts,
    I have the following issue in my BOFC Consolidation which is built up by rules. Deletion of accounts will be not mentioned here. This issue is just a little case:
    Step 1: Take amount from account consolidated participations (dimensional analysis: partner), Audit ID 0PCK01 and write this amount on difference account 1 on Audit ID INVEST10.
    Step 2: Take amount from account retained earnings (no dimensional analysis), Audit ID 0PCK01 and write this amount on difference account 1 on Audit ID INVEST10
    Step 3: Take whole amount from account difference account 1, Audit ID INVEST10. If this amount is positive, write the whole amount (sum on difference account 1) on account goodwill, Audit ID INVEST11. If the amount is negative, write the whole amount (sum on difference account 1) on account badwill, Aufit ID INVEST11.
    I 've tried some days with in my opinion logical possibilities. Dimensional analysis, Thereshold with + oder - signs or different possibilities of creating rules... Always are two amounts (from the first two steps) shown in my schedule. I want to have just the balance of the difference account 1 (which is shown correct on difference account) booked in balance sheet back.
    It would be nice if somebody has any hint for me and my consolidation!
    Cheers
    Udo
    Edited by: Udo Lindemann on Jul 14, 2010 2:36 PM

    Call the number in the update.
    http://www.apple.com/support/macbook_macbookpro/batteryupdate/
    I had a new battery delivered to my door three days after I called them.
    Mort

  • Extended star schema implementation in rpd

    joins of the tables in physical model is as follows
    dim a->fact b
    dim c->dim a
    joins in logical table
    i have created a logical table with dim a & dim c as sources ... and connected this to logical fact with fact b as one of the sources
    now i want to create a measure in the fact table in which i have to use the column from dim c..
    plz suggest me an approach to achieve this ...
    thnks in advance

    regarding aggregation rule,
    it depends on your code.. that you want to write.. because...
    let's go with an example...
    i want to calculate A + B, where A & B are logical columns with aggregation rule sum...
    Now, if you go with logical mapping (A+B), as A & B are already having Aggregation rule this will be carried to the new derived column also... this can be checked by looking at your column image(has aggregation - Sigma symbol)
    better provide your code want to put in..
    And, if it's sum or difference, there is no much difference if you are using logical mapping or physical mapping...
    Edited by: Kishore Guggilla on Sep 20, 2010 1:01 PM

  • Distance between two GPS points

    Is there an inbuilt function in PL/SQL for calulating the distance between two GPS (lat/long) points?
    I'm using Oracle 9i. There's a thing called SDO_GEOM available, but I'm not sure if this is what its used for or if it's the best option.

    If the earth is a complete globe and its circumference is 40000km,
    I make the function as follows.
    create ore replace
    function distance
    (a_lat number,a_lon number,b_lat number, b_lon number)
    return number is
    circum number := 40000; -- kilometers
    pai number := acos(-1);
    a_nx number;
    a_ny number;
    a_nz number;
    b_nx number;
    b_ny number;
    b_nz number;
    inner_product number;
    begin
    if (a_lat=b_lat) and (a_lon=b_lon) then
    return 0;
    else
    a_nx := cos(a_lat*pai/180) * cos(a_lon*pai/180);
    a_ny := cos(a_lat*pai/180) * sin(a_lon*pai/180);
    a_nz := sin(a_lat*pai/180);
    b_nx := cos(b_lat*pai/180) * co s(b_lon*pai/180);
    b_ny := cos(b_lat*pai/180) * sin(b_lon*pai/180);
    b_nz := sin(b_lat*pai/180);
    inner_product := a_nx*b_nx + a_ny*b_ny + a_nz*b_nz;
    if inner_product > 1 then
    return 0;
    else
    return (circum*acos(inner_product))/(2*pai);
    end if;
    end if;
    end;
    I rewrite it by using the factorization and the triangle function's sum and difference formulas:
    cos(x-y) = cos(x)cos(y)+sin(x)sin(y)
    As result, this function is same to the 1st method of Billy Verreynne.
    create or replace
    function distance
    (a_lat number,a_lon number,b_lat number, b_lon number)
    return number is
    circum number := 40000; -- kilometers
    pai number := acos(-1);
    dz number;
    dx2y2 number;
    inner_product number;
    begin
    if (a_lat=b_lat) and (a_lon=b_lon) then
    return 0;
    else
    dz := sin(a_lat*pai/180)*sin(b_lat*pai/180);
    dx2y2 := cos(a_lat*pai/180)*cos(b_lat*pai/180)*cos((a_lon-b_lon)*pai/180);
    inner_product := dz*dz + dx2y2;
    if inner_product > 1 then
    return 0;
    else
    return (circum*acos(inner_product))/(2*pai);
    end if;
    end if;
    end;
    Message was edited by:
    ushitaki

  • Help me start a rogram - Complex nembers

    I have an assignment that includes complex numbers, and I have no idea what a complex number is and where to start. Is there anyone that could help me get started?
    Program details:
    Given a complex number a+ib, we can define the following operations:
    * |a+ib| = square root of (a2+b2) is the absolute value operation.
    * s(a+ib)=sa+isb, where s is a real number, is scaling.
    * the complex conjugate of a+ib is a-ib.
    * (a+ib)+(c+id)=(a+c)+i(b+d) is addition.
    * (a+ib)*(c+id)=(ac-bd)+i(ad+cb) is multiplication. (Notice that scaling is just a special case, where b=0.)
    * do subtraction on your own.
    * (a+ib)/(c+id)=((ac+bd)+i(cb-ad))/(c2+d2) is division. You will have to be careful when dividing - the resulting denominator cannot be equal to 0!
    You are to write a program which contains two separate files.
    The first file will define a Complex class which should include exactly two data members, two constructors, the operations defined above, and a toString method. Important note, the scaling, conjugate, addition, multiplication, subtraction, and division operations all return another complex number. You also must include the appropriate set and get methods. Be sure you comment this class appropriately. Each function should have its own set of comments.
    The second file is an application to test your Complex class as follows: repeatedly read numbers of type double (a, b, c, d, and s), create and print the complex numbers a+ib and c+id, print each numbers absolute value, then create and print the following new complex numbers: s(a+ib), the complex conjugate of a+ib, and the sum, product, difference, and quotient of a+ib and c+id. Continue this loop until the user terminates the application.

    Yes, learn complex numbers. Java is the least of your problems.
    %

  • Duplicate method list on Concurrent Request

    Hi all,
    We have this simple webservice that gets the sum and difference of 2 numbers. It works fine for single, "one after the other" request.
    Environment:
    Windows XP
    Java 1.4
    Tiried Axis 1.1 and Axis 1.4
    Tomcat 5.5.9
    I created a test client that spawns x number of threads and request the page where all the services are listed(http://localhost:8080/WebServiceDemo/Services).
    For a single thread we get this...
    getSum
    getDifference
    but for multiple threads...the results vary but most of the time we get something like
    getSum
    getSum
    getDifference
    getDifference
    We're not sure what's happening. We're thinking that axis might be having difficulties handling concurrent request. Has anyone encountered this? Hopefully the solution is not so painful.
    Thanks

    Bump,
    Tried running this against Axis default methods and we're still getting the same error.

Maybe you are looking for