VEctor: Problem in arithmetical operation

The problem with the following code is that when an element is accessed with v.elementAt() the compilation is OK. But if I try to do some arithmetic operation on the element, it won't compile, giving the message -
VectorDemo.java:36: operator * cannot be applied to java.lang.Object, int
System.out.println("Result: "+v.elementAt(3)*2);
Is it because of <Object> type declaration of Vector? If so how to do arithmetic operation with an element of a vector which may have Double, Float or Integer type of elements in the same vector?
import java.util.*;
class VectorDemo
     public static void main(String args[])
          Vector<Object> v=new Vector<Object>(3,2);
          System.out.println("Initial size: "+v.size());
          System.out.println("Initial capacity: "+v.capacity());
          v.addElement(new Integer(1));
          v.addElement(new Integer(2));
          v.addElement(new Integer(3));
          v.addElement(new Integer(4));
          System.out.println("Capacity after four additions: "+v.capacity());
          v.addElement(new Double(5.45));
          System.out.println("Current capacity : "+v.capacity());
          v.addElement(new Double(6.08));
          v.addElement(new Integer(7));
          System.out.println("Current capacity : "+v.capacity());
          v.addElement(new Float(9.4));
          v.addElement(new Integer(10));
          System.out.println("Current capacity : "+v.capacity());
          v.addElement(new Integer(11));
          v.addElement(new Integer(12));
          System.out.println("First element : "+v.firstElement());
          System.out.println("Last element : "+v.lastElement());
          System.out.println("Find Result: "+v.elementAt(3));     //<------ if replaced with:
                                //System.out.println("Find Result: "+v.elementAt(3)*2);
          if(v.contains(new Integer(3)))
               System.out.println("Vector contains 3.");
          Enumeration vEnum=v.elements();
          System.out.println("\nElements in vector: ");
          while(vEnum.hasMoreElements())
               System.out.println(vEnum.nextElement()+" ");
          System.out.println();
}

Here's the correct code.
import java.util.*;
import java.lang.Number;
class VectorDemo
     public static void main(String args[])
          //initial size is 3, increment is 2
          String s;
          int i=0;
          Vector<Number> v=new Vector<Number>(3,2);
          System.out.println("Initial size: "+v.size());
          System.out.println("Initial capacity: "+v.capacity());
          v.addElement(new Integer(1));
          v.addElement(new Integer(2));
          v.addElement(new Integer(3));
          v.addElement(new Integer(4));
          System.out.println("Capacity after four additions: "+v.capacity());
          v.addElement(new Double(5.45));
          System.out.println("Current capacity : "+v.capacity());
          v.addElement(new Double(6.08));
          v.addElement(new Integer(7));
          System.out.println("Current capacity : "+v.capacity());
          v.addElement(new Float(9.4));
          v.addElement(new Integer(10));
          System.out.println("Current capacity : "+v.capacity());
          v.addElement(new Integer(11));
          v.addElement(new Integer(12));
          System.out.println("First element : "+v.firstElement());
          System.out.println("Last element : "+v.lastElement());
          System.out.println("Result: "+Integer.parseInt(v.elementAt(3).toString())*2);
          if(v.contains(new Integer(3)))
               System.out.println("Vector contains 3.");
          //enumerate the elements in the vector.
          Enumeration vEnum=v.elements();
          System.out.println("\nElements in vector: ");
          while(vEnum.hasMoreElements())
               System.out.println(vEnum.nextElement()+" ");
          System.out.println();
}

Similar Messages

  • Problems with arithmetical operations

    I'm doing mathematical operations on my tables for extracting average records.
    I have an insurance policies table, polizze, and a related clients table, cliente.
    Now I would extract the average number of incidents in a year occurred from the first policy until today.
    If I execute this query:
    SELECT (SUM(c.incFatti() + c.incSubiti())) AS AVERAGE /* incFatti() measures incidents done by the client, incSubiti() incidents suffered */
    FROM cliente c;
    I get 8, e.g. I've a total of 8 incidents in my DB.
    Now, if I execute this one:
    SELECT ROUND(((SYSDATE - MIN(p.data_stipulazione))/365), 2)
    FROM polizza p;
    I get 1.28, e.g. an year and some months passed since the creation of the first policy until today.
    OK, 8 / 1.28 = 6.25 accidents per year and that's what I would obtain with a single query.
    The latter is:
    SELECT ROUND(
    SUM(c.incFatti() + c.incSubiti()) / /* from the first query */
    ((SYSDATE - MIN(p.data_stipulazione))/365), 2) AS AVERAGE /* from the second query */
    FROM cliente c, polizza p
    But I get 31.26! Where do I make a mistake?

    Sure,
    You can use single column single row subqueries as a column source in other queries. You can even correlate the nested sub queries with the outer query e.g.:
    with t1 as (select 7369 x from dual
      union all select 7499 from dual)
    select (select ename from emp where empno = t1.x) ename from t1
    ENAME                         
    SMITH                         
    ALLEN                         
    2 rows selectedI just used two such queries in an expression (your two original queries) which being single column aggregate queries without group by statements were guaranteed to return one row and one column each.
    It's kinda like running them independently and then feeding the results to an expression in a select from dual query.

  • Error while doing MIRO-Overflow for arithmetical operation (type P) in prog

    Hi ,
    I am getting the error while doing the MIRO  as below-
    Runtime Errors         COMPUTE_BCD_OVERFLOW
    Exception              CX_SY_ARITHMETIC_OVERFLOW
    Date and Time          20.05.2009 10:07:03
    Short text
         Overflow during the arithmetical operation (type P) in program "SAPLMRMC".
    What happened?
         Error in the ABAP Application Program
         The current ABAP program "SAPLMRMC" had to be terminated because it has
         come across a statement that unfortunately cannot be executed.
    What can you do?
         Note down which actions and inputs caused the error.
         To process the problem further, contact you SAP system
         administrator.
         Using Transaction ST22 for ABAP Dump Analysis, you can look
         at and manage termination messages, and you can also
         keep them for a long time.
    Error analysis
         An exception occurred that is explained in detail below.
         The exception, which is assigned to class 'CX_SY_ARITHMETIC_OVERFLOW', was not
          caught in
         procedure "MRM_AMOUNT_QUANTITY_PROPOSE" "(FUNCTION)", nor was it propagated by
          a RAISING clause.
         Since the caller of the procedure could not have anticipated that the
    Please let me know how can this be removed.

    Hi,
    There can be some problem with tolerances set in the customizing.
    In my case, I was getting this error because of delivery date variance. The difference between delivery date maintained in PO and invoice date was huge and hence the multiplication of price of PO and difference  of delivery date was huge and that was the reason for error.
    Similarly in your case also, there will be some tolerance limit problem.
    Please check your tolerance limits set in customizing.
    Regards,
    Mihir Popat

  • Overflow for arithmetical operation (type P) in program.

    Hi experts..
    I had developed a report for showing total receipt and issues and confirmed issue.
    of PQ.
    For all the plant is running fine but only for one plant 2050 its going into dump and error is "Overflow for arithmetical operation (type P) in program." and the code line is
    T_EKET-MNG02 = T_EKET-MNG02 * ( t_mdbs-umrez / t_mdbs-umren ).
    MNG02 IS OF TYPE  Data : "Quan", length =13 , decimal = 3.
    initially : value in Mng02 is =  10       and ratio is 11/8 = 1.375
                  and in the debugging the value is   10*1.375 = 13.75
    but... when i am executing it .. its going into dump and after again checking the MNG02 is showing valude --9765133613.881  and the above error.
    what should i do....
    please help..
    i will award the points for every help...
    thanks

    Hi,
    Are you doing any other calculation for field MNG02 in your program?
    I created a small program with the field and values you have mentioned and it gave me the result 13.75 and no short dump.
    Please check following things:
    When short dump occurs, it shows at which line it has occured. Is it showing that the shortdump has occurs on the line you are talking about here or it is somewhere else.
    Also, when shortdump occurs, it shows a "debugging" button at the top. Hit that button and it will show you exactly where the short dump has occured. What ever this statement is, check what are the values of different variables here.
    Check all these and you might get the answer. Let me know if you still have problem.
    Regards,
    RS

  • Overflow during the arithmetical operation (type P) in program SAPLBBP_FRA

    Hi All
    I am receieving the following error the moment I log onto the SRM system via the browser.
    Overflow during the arithmetical operation (type P) in program SAPLBBP_FRAMEWORK
    Please can you advise what could possibly the problem.
    Thanks in Advance
    Regards
    KC

    Hi
    <b>Please go through this SAP OSS Note which will definitely help -></b>
    Note 857137 - MENUDATA: A "short dump" occurs with several role assignment
    <u>Do let me know.</u>
    Regards
    - Atul

  • Using Modulus (%) arithmetic operator with decimals

    When trying to use the arithmetic operator modulus with decimals there seem to be some errors in the results. Is there a restriction on the number/value of decimals that can be used with this operator? Am I perhaps just using it incorrectly?
    example ...
    Double valA= new Double("12.4");
    Double valB = new Double("1236");
    double result = valB.floatValue() % valA.floatValue();
    System.out.println("valB : " + valB );
    System.out.println("valA: " + valA);
    System.out.println("result : " + result);
    produces :
    valB : 1236.0
    valA : 12.4
    result : 8.40003776550293
    But :
    Double valA= new Double("12.5");
    Double valB = new Double("1236");
    double result = valB.floatValue() % valA.floatValue();
    System.out.println("valB : " + valB );
    System.out.println("valA: " + valA);
    System.out.println("result : " + result);
    produces :
    valB : 1236.0
    valA : 12.5
    result : 11.0

    Floating point arithmetic in general is not exact. The problem is that you are expecting exact results.
    In the second example where you use 12.5 and 1236.0 is just so happens that both of those numbers can be represented exactly, so you do get an exact result.

  • Overloading arithmetic operations

    Is there aany way to make a class that would allow overloading of arithmetic operations. I'm getting a bit tired of using
    R = A.add(B.add(C.add(D))); // R = A+B+C+D
    etc. for matrix, complex and vector operations.

    I think there are some preprocessors available that do that, but I've never used one. Google it.

  • ODBC BI Server Bug - arithmetic operation resulted in an overflow

    I am trying to write some really simple .NET code access the Oracle BI Server ODBC driver and it's not working at all.  I've connected fine, however it seems like anything I try to do related to getting database information spits up an error "arithmetic operation resulted in an overflow".
    Here is the code:
    Dim ConnectString As String
    Dim FactoryType As String
    Dim Factory As System.Data.Common.DbProviderFactory
    Dim Connection As System.Data.Common.DbConnection = Nothing
    Dim TablesData As System.Data.DataTable = Nothing
    Dim err As String = ""
    Dim nl As String = Chr(13) + Chr(10)
    Try
        ' Connect to the database via ODBC
        ConnectString = "DSN=BSODBC_7;uid=TheUser10;pwd=************"
        FactoryType = "System.Data.Odbc"
        Factory = System.Data.Common.DbProviderFactories.GetFactory(FactoryType)
        Connection = Factory.CreateConnection
        Connection.ConnectionString = ConnectString
        Connection.Open()
        ' Request a list of tables from the database
        ' ** Tried both with restrictions and without
        ' ERROR on this line:
        ' “Arithmetic operation resulted in an overflow.”
        TablesData = Connection.GetSchema("Tables")
        ' Show the list of tables on the screen in a grid
        ' If it was successful.
        OnScreenGrid.AutoGenerateColumns = True
        OnScreenGrid.DataSource = TablesData
    Catch ex As Exception
        ' Report the error
        err = ex.Message
        If Not (ex.InnerException Is Nothing) Then
            If Not (ex.InnerException.Message Is Nothing) Then
                err = err + nl + nl + ex.InnerException.Message
            End If
        End If
        MsgBox(err, MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Error")
    Finally
        ' Clean up and Close the DB Connection
        If Not (Connection Is Nothing) Then
            Connection.Close()
            Connection.Dispose()
            Connection = Nothing
        End If
    End Try
    Any Thoughts?  Is this a known bug?  Is there a fix?

    I doubt on line
    OnScreenGrid.DataSource = TablesData
    instead of array as TablesData try to take List object and assign it to OnScreenGrid.DataSource
    just in case check this
    DataGridView.AutoGenerateColumns Property (System.Windows.Forms)
    I might be wrong but just check it

  • Power query from ODBC :"DataSource.Error: Arithmetic operation resulted in an overflow"

    Good day
    Everytime I want to pull data into a query from our servers it gives the error "DataSource.Error: Arithmetic operation resulted in an overflow". What is the reason for this error, and how do I get past this bump.
    Thanks in advance
    Arnoux

    Hey Tristan. Thanks I did that yes.
    For some reason my direct MySQL connection does not want to work.
    I get the following error
    DataSource.Error: MySQL: Unable to find a database provider with invariant name 'MySql.Data.MySqlClient'.
    This error may have been the result of provider-specific client software being required but missing on this computer.  To download client software for this provider, visit the following site and choose at minimum 'MySQL Connector/Net':

  • Overflow during the arithmetical operation (type P) in program "SAPLHRPT

    Hi,
    I am currently facing an issue in payroll posting to accounting in international payroll.A run time error "Overflow during the arithmetical operation (type P) in program "SAPLHRPT" occurs. By reducing the amounts on the balance sheet side payroll posting document is created.

    Hi Asad,
    Does you guys enhancemented this program? I think if it`s standard code, it should give you a error message inform you "amount is too large" or something.
    So double click this dump log, to check whether it is a custom code, if yes, to add "TRY CATCH" and give out a message.
    regards,
    Archer

  • Overflow during the arithmetical operation (type P) in program "SAPLV61A

    hi,
        I am getting this error in VA01(sales order)
    Runtime error              Compute_bcd_overflow
    Except                       Cx_sy_arithmetic_overflow.
    Overflow during the arithmetical operation (type P) in program "SAPLV61A
    Error in particular line is.
    1388           ADD  xkomv-kwert  TO komp-mwsbp.
    Please give me the solution with detail decsription.How to solve with step by step.

    Hi,
    Instead of directly assigning the value to xkomv-kbetr. Store the value in a temporary variable of type p length 13 decimals 2 . Multiply by 10^n to get the correct result.
    Then assign the temp value to xkomv-kbetr.
    Sample Code
    DATA : lv_temp TYPE P length 13 decimals 2.
    lv_temp = ( xkwert * 10^n ) / komp-mgame. 
    Then assign lv_temp to xkomv-kbetr.
    To get proper value, you have to multiply or divide by 10^n .
    Regards,
    DPM

  • Problem whit Update Operation, Error UPDATE_ROW_CONFLICT with Oracle DB

    Hello friends!, I have a problem whit UPDATE Operation with a Oracle DataBase, but it is rare because it works in "Java Sun Application Server" and not in Tomcat (5.5.12) , displaying the following error:
    "Error :Number of conflicts while synchronizing: 1 SyncResolver.UPDATE_ROW_CONFLICT row 5 values changed in database"
    part of the file log:
    "SEVERE: Error Description
    java.lang.RuntimeException: Number of conflicts while synchronizing: 1 SyncResolver.UPDATE_ROW_CONFLICT row 5 values changed in database
         at com.sun.data.provider.impl.CachedRowSetDataProvider.commitChanges(CachedRowSetDataProvider.java:878)
         at ido02004.EditPerson.saveButton_action(EditPerson.java:519)
    For any change of columns for table in Data Base.
    The code used in the page (EditPerson.jsp) is:
    public void init() {
    Object pid = getSessionBean1().getCurrentPersonId();
    RowKey personRowKey = ido_personsDataProvider.findFirst("PERSON_ID", pid);
    ido_personsDataProvider.setCursorRow(personRowKey);
    public String saveButton_action() {
    try {
    ido_personsDataProvider.setValue("USER_ID", userDD.getSelected());
    ido_personsDataProvider.setValue("STATUS", statusDD.getSelected());
    ido_personsDataProvider.setValue("NAME", name.getValue());
    ido_personsDataProvider.setValue("FUNCTION", function.getValue());
    ido_personsDataProvider.setValue("ADDRESS", address.getValue());
    ido_personsDataProvider.setValue("EMAIL", email.getValue());
    ido_personsDataProvider.setValue("PHONE", phone.getValue());
    ido_personsDataProvider.setValue("VALUATION", valuation.getValue());
    ido_personsDataProvider.commitChanges();
    catch (Exception ex) {
    log("Error Description", ex);
    error("Error :"+ex.getMessage());
    return null;
    Please, Some idea of why gives the error? Help!
    Thanks in advance!
    Ren�
    P.D. Excuse my English.

    Hi All!
    New Info:
    System.out.println(" date created : "+ido_personsDataProvider.getValue("DATE_CREATED"));
    System.out.println(ido_personsDataProvider.getCachedRowSet().getMetaData().getColumnClassName(13));When these lines are printed in Java Sun Application Server for JSC show this:
    [#|2006-05-05T17:12:50.264-0500|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=15;|
    date created : 2006-04-24 00:00:00.0|#]
    [#|2006-05-05T17:12:50.264-0500|INFO|sun-appserver-pe8.1_02|javax.enterprise.system.stream.out|_ThreadID=15;|
    java.sql.Timestamp|#]
    When these lines are printed in Tomcat show this:
    date created : 2006-04-24
    java.sql.Timestamp
    Why? the values of this date is different in one or another server. Problem of driver JDBC? I use driver: to ojdbc14.jar, in Tomcat for the connection to the BD Oracle. Maybe this originates error UPDATE_ROW_CONFLICT...
    Please, any idea?
    Thanks!

  • Problem in 'INS' operation in fm 'HR_INFOTYPE_OPERATION'

    Hi All,
    I am reading a text file and based on Rate type we have to do insertion or copy.
    If rate type is 'A' then we have to do copy operation with the help of fm 'HR_INFOTYPE_OPERATION'.
    If its 'C' then we have to do operation 'INS'.
    But while calling that fm with 'INS' operation its not inserting and giving an error-
    'Infotype 0171 could not be read for person 00060120 on 09/15/2010'.
    I tried giving other begda also but its not taking.
    I thought of creating new entry in infotype '0171' with this pernr but not able to create.
    Can anyone tell me what is the problem in 'INS' operation in this fm  'HR_INFOTYPE_OPERATION'.
    Thanks,
    Nidhi Srivastava

    Hi Nidhi,
    Did u check the PA30 transaction to insert the 0171 record manually for this employee.
    You can trace back to the error by setting the import parameter DIALOG_MODE of FM to '1', as this will open up the BDC session for PA30 in online mode.
    Thanks,
    RKP

  • Arithmetic operations using Picklist field values

    Hi,
    I tried to multiply a picklist field value as below and wanted to store the result in a field (datatype = Integer or Number) using a workflow which triggers based on the Trigger Event "Before modified record saved".
    Criticality = [<plFrequency_of_Occurrence_ITAG>] * 10
    It throws an error:
    "Update Criticality : Value too long for field 'ZNum_0' (maximum size 16). (SBL-DAT-00235)(SBL-ODS-00500)"
    Can't we do arithmetic operations on the Picklist fields? I believe this is because the values are being stored as text??
    Do we have a function to convert the character field to numeric before we perform any arithmetic operations?
    Thanks,
    Sriram

    Hi,
    You're right, you can't perform arithmetic operations with a number and a text. That's why you get the error.
    Today, there's no function you can use to convert a text to a number.
    You'll need to create a SR asking for a Change Request.
    Regards,
    Max

  • [nQSError: 22023] An arithmetic operation is being carried out on a non-num

    Hi All,
    I have created a logical column for rolling period based on a measure. I have used newly created rolling period column to create another column. I have checked the global consistency there were no errors in rpd. I have uploaded the rpd, when I was trying to expand that table in Answers it is giving an error *"State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 22023] An arithmetic operation is being carried out on a non-numeric type. (HY000)"*
    The base measure has aggregation rule. Please help to find resolve this issue.
    Thanks in advance.

    Rolling Amount- "PeriodRolling("Core"."Fact - Sales - Orders"."Order Amount" , -10, 0)"
    Amount- "case when VALUEOF("No_of_Days"."No_of_days") <= 10 then ( "Core"."Fact - Sales - Orders"."Rolling Amount" / 10) * VALUEOF("No_of_Days"."No_of_days") else "Core"."Fact - Sales - Orders"."Order Amount" / VALUEOF("No_of_Days"."No_of_days") end"
    I have created above two measures.
    Expand table means we need click on + symbol besides the table name to select columns, it is not allowing me to click on that + sysmbol.

Maybe you are looking for

  • How to delete photos in Icloud

    How to delete photos in icloud

  • Battling Hardware MPE, Episode 2: Chunky Blurs

    Round Two of my hardware acceleration MPE tests... When using direct export with hardware MPE, any effect that renders a blurred alpha channel (Fast Blur, Gaussian Blur, etc.) creates an extremely ugly/chunky/unusable result. The source footage and s

  • HOW TO FIX WARNING  "SELECT QUERY"

    CAN SOMEBODY SUGGEST ME AN EASY SOLUTION............EXCEPT FETCH OR FIELD GROUP ONE. I AM SELECTING 6 FIELDS FROM FEBEP TABLE INTO AN INTERNAL TABLE ,BUT THE PROBLEM IS THAT WHILE INSPECTING CODE I AM GETTING AN ERROR WARNING THAT FEBEP "TABLE IS TOO

  • Clustering etc

    Hi, Sorry for long post and thanks for patience (read at leas first question (-:) I would like to ask abt. session beans with Local interface in cluster enviroment and a WEB want to access such bean. I can guess that with stateless beans the situatio

  • ESS WebDynpro Bank Information

    Hi, When we run ESS Bank Information WebDynpro we are getting following error... An exception that could not be caught occurred., error key: RFC_ERROR_SYSTEM_FAILURE com.sap.tc.webdynpro.modelimpl.dynamicrfc.WDDynamicRFCExecuteException: An exception