Calculate sum of long integer!

Hi!
Im new to java and just started to learn but have a little problem. What I want to know is how I can get a long integer from the user and then caculate the sum of the separate numbers? I thinking I would use som sort of array and then calculate from there. The thing is Im use to ada programminglanguage so I understand the problem but dont really know how to tackle the problem in java.
So if someone could help I would be grateful!
//Viktor

Julingo wrote:
"I guess you have a handle on how to get an integer from the user then? Can you write the code to get an integer from the user and display it? And "long" and "int" are two different things - which one are you talking about, a 32 bit number or a 64 bit number?"
Yes, I do know how to get an integer from a user and display it. So far so good :) If I wasnt that clear it is a "long" 64 bit Im trying to get from user and then caculate the sum like this:
enter integer: 1234567
digits are 1 2 3 4 5 6 7 and the sum is 28
/ViktorOk, so, you know how to get input from the user and display it - so - look at the API for the String class and think about your "I think I'll use an array" idea and see what you find there
Edited by: tsith on Sep 9, 2008 7:49 PM

Similar Messages

  • Access Long Integer

    I need to query a Long Integer from my app. I have tried using int and long but with no luck. I get a type mismatch every time it tries to execute.
    This does not work
                        StringTokenizer st = new StringTokenizer(results.getSelectedValue().toString());
                        int plNum = Integer.parseInt(st.nextToken());
                        try{
                             s = con.createStatement();
                             s.execute("SELECT * FROM Packlists WHERE Packlist = '" + plNum + "'");
                        }catch(Exception e){
                             System.out.println(e);
                        }However, in a different part of my code this does:
                             s.execute("SELECT Current.Current FROM Current");
                             rs = s.getResultSet();
                             rs.next();            //eleminates invalid cursor state error
                             int number = Integer.parseInt(rs.getString(1)) + 1;
                             s = con.createStatement();
                             s.executeUpdate("UPDATE Current SET Current = '" + number + "'");any sugestions?

    StringTokenizer st = new StringTokenizer (results.getSelectedValue ().toString ());
    // System.out.println (st.hasMoreTokens ());
    int plNum = Integer.parseInt (st.nextToken ());
    // System.out.println (plNum);
    try {
        s = con.createStatement ();
        String query = "SELECT * FROM Packlists WHERE Packlist = '" + plNum + "'";
        // System.out.println (query);
        // how about executeQuery here?
        s.execute (query);
    } catch (Exception e) {
        System.out.println (e);
    }Kind regards,
      Levi

  • How to calculate sum in jtable

    Hi,i want to ask.Can you teach me how to calculate sum in jtable?For example i got rows of qty,price and total.The total is null unless the user enter value in qty,and when the user press enter key in the qty,the sum will be displayed in the total.Thanks a lot..

    Calculate the sum on the fly when the tableModel is updated (setValueAt() ) or let your row Object deal with it.

  • How to calculate sum of the fields in adobeforms

    Hello Experts
    can  i know how to calculate sum of fields in the adobe form.  I have few fields to be summed in total field.
    Regards

    Hello Surendra,
         Suppose you are having 4 fields and the 4th field is the TOTAL field.
         Write the below Javascript on the Initialize event of TOTAL field as shown below.
    Remember that if you use just "+" sign without Number() or ParseInt() function it acts like String Concatenation.
    this.rawvalue = Number( this.parent.field1.rawvalue ) +
                          Number( this.parent.field2.rawvalue ) +
                          Number( this.parent.field3.rawvalue ) ;
    You can also write is as shown below.
    this.rawvalue = parseInt( this.parent.field1.rawvalue ) +
                             parseInt( this.parent.field2.rawvalue ) +
                             parseInt( this.parent.field3.rawvalue ) ;

  • How to calculate SUM from multiple numbers in one cell

    Is it possible to calculate SUM if I want to put multiple numbers in one cell?
    Many thanks in advance

    you can sum cell by using the sum() function.
    you can sum a row:
    =sum(1:1)
    will sum ALL cells in row 1
    you can sum a column:
    =sum(C)
    will sum all cells in column C
    you can sum a list of cells:
    =sum(A1, C5, E76, B1:5)
    will add together cells A1, C5, E76, B1, B2, B3, B4, and B5

  • How to calculate sum of quantities of same item in po release using form personalization?

    I am doing one form personalization in which an item can be entered multiple times in with different released quantity and need by date.
    I want to calculate the sum of release quantity of items.
    How I can achieve this using form personalization?
    Thanks
    Sunny

    Hi Gayatri,
    I'm not too sure why this isn't working as the logic seems correct.
    Here's another way to do this:
    1) Create another formula and place this on the Details Section:
    whileprintingrecords;
    numbervar x;
    if onfirstrecord then
    x := {Field_to_summarize}
    else if {ExcisePur.ItemCode} <> Previous({ExcisePur.ItemCode}) And {ExcisePur.Batchnum} <> Previous({ExcisePur.Batchnum}) then
    x := x + {Field_to_summarize};
    2) Create another formula and place this on the Report Footer:
    whileprintingrecords;
    numbervar x;
    -Abhilash

  • Javascript auto calculate sum in form

    Hello all,
    I have a question for you, probably pretty simple but I don't know JavaScript well enough. What I have is four TextFields in a form. I want the value of the first two (let's call them A and B) to multiply and autopopulate the total in the fourth TextField (D). In the third TextField (C) I want the number entered to be multiplied by 3.25 and be added to the total in the 4th TextField. In other words A*B+(C*3.25)=D
    In plain English, this is for a community garden registration. Number of plots times Fee per plot (which varies based on income level) plus optional bales of hay at $3.25 = _____________.
    Any JavaScript experts out there who can help me?
    Thanks much!
    Dave

    Thanks, Gramps, but not exactly what I was looking for. What I have is 4 TextFields, no radio buttons, etc. I want the first two to multipy, and the third I want to calculate the number typed in times 3.25 adding the sum of the three to the fourth box. I've come close to finding some JavaScript online, but can't quite figure out the exact JavaScript coding to do this. I have a feeling it is simple, just that I know next to nothing about JavaScript and was hoping to find a quick solution until I do have the chance to learn more. Anyone?

  • Calculate Sum Tricky one

    Hello Gurus,
    A text file has data is in the following manner
    I have read the file and all properly the only problem
    here is summing up the data so below is how my data looks.
    Please make a note this is not stored in DDIC database table it will be read in an Internal table
    Also Col3 is not a integer so I cannot use COLLECT
    Please suggest a way out to handle this tricky part.
    I don;t thik At New On change will work please try this program using the same test data given below , please send me the abap code if you are able to crack this nut.
    Col1 Col2 Col3
    ABC A 1
    ABC A 2
    ABC B 3
    BBC A 4
    BBC A 5
    I want to Sum up COL3 by grouping COL1 and COL2
    so First Record = ABC A 3 ( 1+ 2)
    Second Record = ABC B 3
    Third Record = BBC A 9 ( 4 + 5 )
    Please let me know I tired many logic but nothing seems to be working.. your help is greatly apprecaited .
    Points guranteeed !!
    Reagrds,
    Aryan

    Hi Aryan,
    I was able to do the sum... check the code below...hope it helps..
    TYPES: BEGIN OF TY_ITAB,
            COL1(3) TYPE C,
            COL2    TYPE C,
            COL3(2)    TYPE C,
      END OF TY_ITAB.
    DATA: ITAB TYPE TABLE OF TY_ITAB,
          IT_FINAL TYPE TABLE OF TY_ITAB WITH HEADER LINE,
          WA TYPE TY_ITAB,
          WA1 TYPE TY_ITAB,
          COUNT TYPE I,
          SUM TYPE I,
          FLAG TYPE FLAG.
    WA-COL1 = 'ABC'.
    WA-COL2 = 'A'.
    WA-COL3 = '1'.
    APPEND WA TO ITAB.
    WA-COL1 = 'ABC'.
    WA-COL2 = 'A'.
    WA-COL3 = '1'.
    APPEND WA TO ITAB.
    WA-COL1 = 'ABC'.
    WA-COL2 = 'A'.
    WA-COL3 = '2'.
    APPEND WA TO ITAB.
    WA-COL1 = 'ABC'.
    WA-COL2 = 'B'.
    WA-COL3 = '23'.
    APPEND WA TO ITAB.
    WA-COL1 = 'ABC'.
    WA-COL2 = 'A'.
    WA-COL3 = '10'.
    APPEND WA TO ITAB.
    WA-COL1 = 'ABC'.
    WA-COL2 = 'B'.
    WA-COL3 = '12'.
    APPEND WA TO ITAB.
    WA-COL1 = 'ABC'.
    WA-COL2 = 'B'.
    WA-COL3 = '9'.
    APPEND WA TO ITAB.
    WA-COL1 = 'ABC'.
    WA-COL2 = 'A'.
    WA-COL3 = '2'.
    APPEND WA TO ITAB.
    SORT ITAB BY COL1 COL2.
    LOOP AT ITAB INTO WA.
      READ TABLE IT_FINAL WITH KEY COL1 = WA-COL1
                                   COL2 = WA-COL2.
      IF SY-SUBRC = 0.
        CONTINUE.
        ENDIF.
      CLEAR: WA1 , SUM ,FLAG.
      READ TABLE ITAB INTO WA1 WITH KEY COL1 = WA-COL1
                                       COL2 = WA-COL2
                                       BINARY SEARCH.
      IF SY-SUBRC = 0.
        COUNT = SY-TABIX + 1.
        SUM = WA1-COL3.
        CLEAR WA1.
        WHILE ( FLAG NE 'X').
          READ TABLE ITAB INTO WA1 INDEX COUNT.
          IF WA1-COL1 = WA-COL1 AND WA1-COL2 = WA-COL2.
            SUM = SUM + WA1-COL3.
            COUNT = SY-TABIX + 1.
          ELSE.
            FLAG = 'X'.
          ENDIF.
        ENDWHILE.
      ENDIF.
    IT_FINAL-COL1 = WA-COL1.
    IT_FINAL-COL2 = WA-COL2.
    IT_FINAL-COL3 = SUM.
    APPEND IT_FINAL.
    CLEAR IT_FINAL.
    ENDLOOP.
    LOOP AT IT_FINAL.
      WRITE:/ IT_FINAL-COL1 , 10 IT_FINAL-COL2 , 20 IT_FINAL-COL3.
      ENDLOOP.

  • 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

  • Calculate sum of under estimates

    I have a 2008 r2 cube with 2 measures EstmatedTime and ActualTime and a date dimension.  I need to calculate the sum of the under estimates.  So if my estimated hours on the 1st, 2nd and 3rd are 10, 10, 10  and my actual hours are 11, 12,
    7, I need to return 3 as the sum of the under estimates for the period.  Is there a way to do this using MDX, or do I need to do it in the ETL?
    John Schroeder

    Hi JS,
    Considering both the measures are at same granularity, try the below:
    Create a calculated member :
    with member [Measures].[Diff] as
    iif(isempty([Measures].[EstmatedTime])=TRUE and isempty([Measures].[ActualTime]=TRUE,null,
    iif([Measures].[ActualTime] > [Measures].[EstmatedTime],[Measures].[ActualTime] - [Measures].[EstmatedTime],0))
    Now the result would be fine at Date level, but at a higher level say Month the result would not as expected, as the calculated member [Measures].[Diff] would be calculated after aggregating EstmatedTime and ActualTime at month level. In order to fix this
    define a scope.
    Scope( [DimDate].[DateHierarchy].[Month],[Measures].[Diff]);
    This = Sum( Descendants( [DimDate].[DateHierarchy].CurrentMember,[DimDate].[DateHierarchy].[Date]),[Measures].[Diff]);
    End Scope;
    Similarly define scope for all higher datehierarchy levels.
    Saurabh Kamath

  • Require a function module to calculate sum of the quantity based on GRNDATE

    hi friends,
    I need to calculate the sum of the quantity based on GRN DATE and invoice date.
    the invoice date given in select-options should be captured by program and from the previous day it need to retrieve the GRN dates and corresponding quantities and i need to do the summation of all these quantities can anybody tell any function module.
    Thanks in advance.

    Try function MD_CONVERT_MATERIAL_UNIT
    the table of UOM's is MARM.
    Doug

  • Calculate SUM based in condition in iTAB

    Hi all,
    I have the ITAB as follows.
    wa_mseg-mblnr = '5000000130'.
    wa_mseg-mjahr = '2008'.
    wa_mseg-bwart = '901'.
    wa_mseg-dmbtr = '00000005000'.
    wa_mseg-bpmng = '00000000100'.
    wa_mseg-ebeln = '1059200855'.
    wa_mseg-ebelp = '00010'.
    APPEND wa_mseg to itab_mseg.
    wa_mseg-mblnr = '5000000131'.
    wa_mseg-mjahr = '2008'.
    wa_mseg-bwart = '902'.
    wa_mseg-dmbtr = '00000002500'.
    wa_mseg-bpmng = '00000000050'.
    wa_mseg-ebeln = '1059200855'.
    wa_mseg-ebelp = '00010'.
    APPEND wa_mseg to itab_mseg.
    wa_mseg-mblnr = '5000000132'.
    wa_mseg-mjahr = '2008'.
    wa_mseg-bwart = '901'.
    wa_mseg-dmbtr = '00000002500'.
    wa_mseg-bpmng = '00000000050'.
    wa_mseg-ebeln = '1059200855'.
    wa_mseg-ebelp = '00010'.
    APPEND wa_mseg to itab_mseg.
    now i want to add the BPMNG for the BWART = 901
                                   DMBTR   for the BWART = 901
    ans same thing  for the BWART = 902.
    how do i calculate the SUM based on condition.

    now i want to add the BPMNG for the BWART = 901
    DMBTR for the BWART = 901
    ans same thing for the BWART = 902.
    how do i calculate the SUM based on condition.
    Hi, you can loop de internal table and do a control cut by "bwart". For doing that the order of the fields of your internal table must change.
    If you have:
    1st.mblnr
    2nd.mjahr
    3rd.bwart
    you have to change to:
    1st.bwart
    2nd.mblnr
    3rd.mjahr
    So in the loop you will can do like this.
    loop at itab.
    aux_sum = itab-BPMNG + aux_sum.
    at end of bwart.
    * Here you will have de SUM for BWART.
    * Then you clear aux_sum for the next different BWART.
    endat.
    endloop.
    hope this help you.
    Andrew83

  • IF statement in Calculated Field for Share point, doesnt calculate sum in my Excel Pivot table.

    Hi Everyone
    I used this in SP calculated column field.
    =IF([Shift Sched]="1pm to 10pm","0",IF([Shift Sched]="2pm to 11pm","1",IF([Shift Sched]="3pm to 12am","2",IF([Shift Sched]="4pm to 1am","3",IF([Shift Sched]="5pm to 2am","4",IF([Shift
    Sched]="6pm to 3am","5",IF([Shift Sched]="7pm to 4am","6",IF([Shift Sched]="8pm to 5am","7",IF([Shift Sched]="9pm to 6am","8",IF([Shift Sched]="10pm to 7am","8",IF([Shift
    Sched]="11pm to 8am","7",IF([Shift Sched]="12pm to 9am","6",IF([Shift Sched]="1am to 10am","5",IF([Shift Sched]="2am to 11am","4",IF([Shift Sched]="3am to 12pm","3",IF([Shift
    Sched]="4am to 1pm","2",IF([Shift Sched]="5am to 2pm","1",IF([Shift Sched]="6am to 3pm","0",IF([Shift Sched]="7am to 4pm","0",IF([Shift Sched]="8am to 5pm","0",IF([Shift
    Sched]="9am to 6pm","0",IF([Shift Sched]="10am to 7pm","0",IF([Shift Sched]="11am to 8pm","0",IF([Shift Sched]="12pm to 9pm","0"))))))))))))))))))))))))    
    it was able to work fine however my issue is when i extract the information to excel and use a pivot table the table is not able to calulate the sum of the value for this field. Can you please help me with this. this is for an Attendance traker for Night
    Differential pay for employees. they create a daily log of their shift schedule and if i summarize this in pivot the value in the calculated field for this is not getting the sum.
    Thanks,
    Norman

    Hi Everyone
    I used this in SP calculated column field.
    =IF([Shift Sched]="1pm to 10pm","0",IF([Shift Sched]="2pm to 11pm","1",IF([Shift Sched]="3pm to 12am","2",IF([Shift Sched]="4pm to 1am","3",IF([Shift Sched]="5pm to 2am","4",IF([Shift
    Sched]="6pm to 3am","5",IF([Shift Sched]="7pm to 4am","6",IF([Shift Sched]="8pm to 5am","7",IF([Shift Sched]="9pm to 6am","8",IF([Shift Sched]="10pm to 7am","8",IF([Shift
    Sched]="11pm to 8am","7",IF([Shift Sched]="12pm to 9am","6",IF([Shift Sched]="1am to 10am","5",IF([Shift Sched]="2am to 11am","4",IF([Shift Sched]="3am to 12pm","3",IF([Shift
    Sched]="4am to 1pm","2",IF([Shift Sched]="5am to 2pm","1",IF([Shift Sched]="6am to 3pm","0",IF([Shift Sched]="7am to 4pm","0",IF([Shift Sched]="8am to 5pm","0",IF([Shift
    Sched]="9am to 6pm","0",IF([Shift Sched]="10am to 7pm","0",IF([Shift Sched]="11am to 8pm","0",IF([Shift Sched]="12pm to 9pm","0"))))))))))))))))))))))))    
    it was able to work fine however my issue is when i extract the information to excel and use a pivot table the table is not able to calulate the sum of the value for this field. Can you please help me with this. this is for an Attendance traker for Night
    Differential pay for employees. they create a daily log of their shift schedule and if i summarize this in pivot the value in the calculated field for this is not getting the sum.
    Thanks,
    Norman

  • How to use decode to calculate sum for different date range

    I'm stuck with decode() function:
    I have a table like this:
    (project_id, approve_date, value, builder_code)
    I want to write a SQL query to get sum of values for different month of the approve_date, and group by builder_code)
    The result is like this:
    builder_code Sum(value)_Sep-03 Sum(value)_Oct-03 Sum(value)_Nov03
    1001 1,299 1,322 990
    1002 3,332 1,222 333
    I tried to use decode for this question but could not get the answer.
    Thanks a lot

    I don't think you need a DECODE() here. I'd do something like this-
    create table builder (
        project_id number,
        approve_date date,
        value        number,
        builder_code number
    insert into builder values( 1, to_date('09-01-2003', 'MM-DD-YYYY'), 100, 990 )
    insert into builder values( 2, to_date('09-03-2003', 'MM-DD-YYYY'), 150, 990 )
    insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 990 )
    insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 333)
    SELECT sept.builder_code, sept.sept_sum, oct.oct_sum
    FROM (SELECT builder_code, sum(value) sept_sum
            FROM builder
           WHERE approve_date >= to_date('09-01-2003','MM-DD-YYYY')
             AND approve_date < to_date('10-01-2003','MM-DD-YYYY')
           GROUP BY builder_code) sept,
         (SELECT builder_code, sum(value) oct_sum
            FROM builder
           WHERE approve_date >= to_date('10-01-2003','MM-DD-YYYY')
             AND approve_date < to_date('11-01-2003','MM-DD-YYYY')
           GROUP BY builder_code) oct
    WHERE oct.builder_code(+) = sept.builder_code
    BUILDER_CODE   SEPT_SUM    OCT_SUM
             333        250
             990        500Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • How to Calculate sum for the selected rows in ALV gird using custom button

    Hi I am trying to implement an ALV Grid display where the user can select few rows in the output and if he click on some custom button he should get the sum for only those rows.
    Can anyone give me some idea regarding this.
    Thanks in advance

    While building the fieldcatalog for amount field use gt_fieldcat-do_sum = 'X'. And use the below for doc type sorting and subtotal.
    *  ALV data declarations
      data: it_sortcat   type slis_sortinfo_alv occurs 1,
            wa_sort like line of it_sortcat.
    perform build_sortcat.
    *&      Form  build_sortcat
    *       Build Sort catalog
    FORM build_sortcat .
      wa_sort-spos      = 1.
      wa_sort-fieldname = 'EBELN'.
      wa_sort-SUBTOT    = 'X'. "subtotals any totals column by this field
    *  gd_sortcat-tabname
      APPEND wa_sort TO it_sortcat.
      wa_sort-spos      = 2.
      wa_sort-fieldname = 'EBELP'.
    *  gd_sortcat-tabname
      APPEND wa_sort TO it_sortcat.
    ENDFORM.                    " build_sortcat
    call function 'REUSE_ALV_LIST_DISPLAY'
           exporting
                i_callback_program      = gd_repid
                i_callback_top_of_page   = 'TOP-OF-PAGE'
                is_layout               = gd_layout
                it_fieldcat             = fieldcatalog[]
                it_sort                 = it_sortcat
                i_save                  = 'X'
           tables
                t_outtab                = it_ekko
           exceptions
                program_error           = 1
                others                  = 2.
    Regards,
    Chandru

Maybe you are looking for

  • String properties

    String cat = name.substring(0, name.lastIndexOf('\\')); String cat1 = cat.substring(cat.lastIndexOf('\\')+1)); Can anyone explain to be the difference between the 2? thanks.

  • Using Charm with CTS+

    Hi experts, I would know if it's possibile configure the change request management to manage non-abap transport. I have a PI landascape (abapjava) where I configure the CTS. I would know if I can implement CHARM in my solutionmanager in order to mana

  • Simple Question for R/3

    Hi, Alls Question1, what roles and authroz. I need for CCMS alerts in R3 system and auto-reaction method seutp Question2, Will I have to configure SMTP first for CCMS (Auto-re-action method) Question3, Sould I need to change any profile for that ? Pl

  • Moving iPhoto Pictures to a PC

    My spouse uses a PC at work, and she would like to transfer her iPhoto photos to her PC. The only way that I can think of to do this is to export her entire library (about 6,000 photos) to a stick or other external drive, then have her copy them onto

  • Camera Extras app for Lumia 900

    I can't find the Camera extras anywhere. I do appear to have the Play To (DLNA) and other features like tethering. Am I doing something wrong, or are those seperate updates that will come at a later date?