Precision with float and double values

Hi, does anyone knows how can i get more precise calculations with floating point numbers? Let's see an example:
public class Teste {
public static void main(String args[]) {
float i = 0;
while (i<=10) {
System.out.println(i);
i=i+0.1f;
/* output
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.70000005
0.8000001
0.9000001
1.0000001
1.1000001
1.2000002
1.3000002
1.4000002
1.5000002
1.6000003
1.7000003
1.8000003
1.9000003
2.0000002
2.1000001
2.2
2.3
2.3999999
2.4999998
2.5999997
2.6999996
2.7999995
2.8999994
2.9999993
3.0999992
3.199999
3.299999
3.399999
3.4999988
3.5999987
3.6999986
3.7999985
3.8999984
3.9999983
4.0999985
4.1999984
4.2999983
4.399998
4.499998
4.599998
4.699998
4.799998
4.8999977
4.9999976
5.0999975
5.1999974
5.2999973
5.399997
5.499997
5.599997
5.699997
5.799997
5.8999968
5.9999967
6.0999966
6.1999965
6.2999964
6.3999963
6.499996
6.599996
6.699996
6.799996
6.899996
6.9999957
7.0999956
7.1999955
7.2999954
7.3999953
7.499995
7.599995
7.699995
7.799995
7.899995
7.9999948
8.099995
8.199995
8.299995
8.399996
8.499996
8.599997
8.699997
8.799997
8.899998
8.999998
9.099998
9.199999
9.299999
9.4
9.5
9.6
9.700001
9.800001
9.900002
*/

http://forum.java.sun.com/thread.jsp?forum=31&thread=357174

Similar Messages

  • Confused with float and double

    Hi,
    I have done the following program which is supposed to deal with temperature and scales.
    import java.math.BigDecimal;
    public class Temperature {
         private float temp;
         private char scale;
         public static void main(String args[]) {
              Temperature t = new Temperature(40.5, 'F');
              System.out.println(t.getCTemperature());
         public Temperature() {
              temp = 0;
              scale = 'C';
         public Temperature(float pTemp) {
              temp = pTemp;
              scale = 'C';
         public Temperature(char pScale) {
              temp = 0;
              scale = 'C';
         public Temperature(float pTemp, char pScale) {
              temp = pTemp;
              scale = pScale;
         public float getCTemperature() {
              if (scale == 'C') {
                   return temp;
              } else {
                   float celciusTemp = 5 * (temp - 32) / 9;
                   BigDecimal bd = new BigDecimal(celciusTemp);
                   return bd.setScale(1, BigDecimal.ROUND_HALF_UP).floatValue();
    }When I try to compile I get the following error :
    F:\programs\ch4>javac Temperature.java
    Temperature.java:8: cannot find symbol
    symbol  : constructor Temperature(double,char)
    location: class Temperature
    Temperature t = new Temperature(40.5, 'F');
    *^*
    *1 error*
    I don't understand why the number 40.5 is considered like a double and that I can't use Temperature(float, char);
    If I'm not mistaken the compiler is asking for a constructor like Temperature(double, char) right ??
    thanks.

    Can I second Mr TuringPest, and Sir J.Bloch... Do NOT use floats, unless of course you have a really really good reason. Internally, java does all it's floating point arithmetic in doubles anyways, so you're just shooting yourself in the accuracy-foot by forcing it to: promote to double to calculate, "narrow" result back to float... promote, narrow ... promote, narrow ... promote, narrow ... The net result can be astoundingly inaccurate... So just use doubles.

  • Problems with convertNumber and Double values

    I've serious troubles using convertNumber with Double data in input fields.
    While output formatting works fine, the outputted string fails to be converted back - I get conversion errors.
    So the value that is written to the input field generates a conversion error being submitted! This is not good practice!
    I've found out the following: (I use german locale, so following examples containing ',' means decimal point)
    <f:convertNumber pattern="##0.00" />generates the right output, eg. for Double(20.50) - "20,50", but this value ("20,50") will not be parsed using the above pattern! Only values with non zero last minimum fractional digit (eg "20,51", "20,59", ... ) will be parsed!
    In addition, the above pattern doesn't parse numberstrings that don't contain all significant digits.
    For example an input of "20" will not be parsed to "20.00"!
    Maybe this is not the right forum for that problem, since i think this is a general java formatting problem (?).
    But as the problem arised by using the convertNumber tag and acting like this on numeric input fields is not very comfortable, I liked to post this here. Maybe someone can give me some advice?

    I also have found this problem, except that in my experience it is the decimal part that must be non-zero, not just the last digit of the decimal part. So with a pattern of "0.00" the string "1.50" (one and a half) will be accepted whereas the string "1.00" will not.
    My guess (just a guess) is that it is related to the documented behaviour of the DecimalFormat object when it parses a number. According to the documentation:
    The most economical subclass that can represent the number given by the string is chosen. Most integer values are returned as Long objects, no matter how they are written: "17" and "17.000" both parse to Long(17). Values that cannot fit into a Long are returned as Doubles. This includes values with a fractional part, infinite values, NaN, and the value -0.0. DecimalFormat does not decide whether to return a Double or a Long based on the presence of a decimal separator in the source string. Doing so would prevent integers that overflow the mantissa of a double, such as "10,000,000,000,000,000.00", from being parsed accurately. Currently, the only classes that parse returns are Long and Double, but callers should not rely on this. Callers may use the Number methods doubleValue, longValue, etc., to obtain the type they want.
    Which means that "1.50" will be returned as a Double while "1.00" will be returned as a Long. Perhaps there is then a class-cast exception whie trying to use this value?
    If this is indeed the problem, the solution is to use the getDouble() method of the parsed Number to create the Double to be returned, but this is for the implementer to do - not the user!

  • Validating a JTextField having a float or double value.

    Hello,
    I need help in validating a JTextfield which will accept a float or double value because it the deposit field and it shouldn't be of length more than 7 before the decimal and 2 after the decimal.That is it should be of length 10.I have written the following code for the validation.
    txtDeposit.addKeyListener(new KeyAdapter(){
    //Accept only integer value
              public void keyTyped(KeyEvent e){
              char c = e.getKeyChar();
    if((txtDeposit.getText()).length() == 10)
              if (!(Character.isDigit(c)))
              if(!Character.isISOControl(c))
              getToolkit().beep();
              e.consume();
              });//end of txtDeposit*/
    Please help.

    use javax.swing.InputVerifier
    import java.awt.BorderLayout;
    import java.awt.Toolkit;
    import javax.swing.InputVerifier;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    public class VerifyInput extends JFrame {
        public VerifyInput(){
            super("Input Verifier");
            this.setSize(200, 200);
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JTextField txt = new JTextField();
            txt.setInputVerifier(new CheckInput());
            this.getContentPane().add(txt, BorderLayout.NORTH);
            JButton btnMoveFocus = new JButton("CLick");
            this.getContentPane().add(btnMoveFocus, BorderLayout.SOUTH);
        public static void main(String[] args) {
            VerifyInput f = new VerifyInput();
            f.setVisible(true);
        class CheckInput extends InputVerifier{
            private int lengthBeforeDot = 7;
            private int lengthAfterDot = 2;
            public CheckInput(){
            public CheckInput(int lengthBeforeDot, int lengthAfterDot){
                this.lengthAfterDot = lengthAfterDot;
                this.lengthBeforeDot = lengthBeforeDot;
            public boolean verify(JComponent input) {
                boolean correct = true;
                try {
                    JTextField tField = (JTextField) input;
                    String text = tField.getText();
                    if(text.length() == 0){
                        return true;
                    if ((correct = isDoubleOrFloat(text))) {
                        correct = isFormatCorrect(text);
                } finally {               
                    if(!correct){
                        Toolkit.getDefaultToolkit().beep();
                        System.out.println("Not Correct");
                    }else{
                        System.out.println("Correct");
                return correct;
            private boolean isDoubleOrFloat(String text){
                try{
                    Double.parseDouble(text);
                }catch(NumberFormatException nfe){
                    return false;
                return true;
            private boolean isFormatCorrect(String text){
                int dotIndex = text.indexOf('.');
                if(dotIndex < 0){
                    return text.length() <= lengthBeforeDot;
                String beforeDecimal = text.substring(0, dotIndex - 1);
                if(beforeDecimal.length() >= lengthBeforeDot){
                    return false;
                String afterDecimal = text.substring(dotIndex + 1);
                if(afterDecimal.length() > lengthAfterDot){
                    return false;
                return true;
    }

  • Float and Double - 5.1 divide by 3.0

    Hi everyone,
    I am quite new to java programming in term of using it. I wrote a test class to learn about float and double. However when I wrote the below code, I got a strange result. So, I wonder if java's float and double have any kind of exception I should be aware of. This won't happen if I just change from 3 to other numbers. Any suggestion? Thanks in advance.
    public class MathTest {
    public static void main (String args[]) {
    float f1 = 5.1F;
    float f2 = 3.0F;
    double d1 = 5.1;
    double d2 = 3.0;
    System.out.println("Float result : " + f1/f2);
    System.out.println("Double result : " + d1/d2);
    Result:
    Float result : 1.6999999
    Double result : 1.7

    This is due to the way that binary numbers convert to digital numbers and is expected. See these threads for explanations:
    http://onesearch.sun.com/search/onesearch/index.jsp?qt=%2Bprecision+%2Bwrong+double&col=developer-forums&rf=0&chooseCat=allJava&subCat=siteid%3Ajava

  • Problem with QofQ and Null Values

    Just converted from CF5 to CF7. Finally figured out what was
    causing the error message :
    "The value "" cannot be converted to a number" when running a
    QofQ. It happens whenever there is a NULL (and I think a ZERO)
    value in the QofQ. I'm using the QofQ in a seperate chart program.
    The main query merges data from a store and a region table.
    I'm doing a LEFT OUTER JOIN to combine the REGION with the STORE,
    AND so that stores with NO SALES for a given day will show up as
    ZERO. On the main report, when I don't use a QofQWhen grouping by
    DAY or MONTH, I can test the value in the CFOUTPUT for NULL or ZERO
    and display "0" or "N/A" on the report.
    But when I try to chart it, using a QofQ to read in the
    values from the main query, and format the numbers, I get this
    error message. I've tried using the CAST function, using FLOAT,
    DOUBLE, BIGINT, etc., but still get same error message.
    The only way I could fix this is to add a WHERE statement to
    the QofQ, that only includes sales values greater than ZERO. But
    then, I have gaps in my chart because stores with NO SALES for a
    given day or MONTH don't appear. Because they are removed from the
    query. The whole point of LEFT JOINS is to include items with no
    values (or NULL) values.
    Does anyone know if it's possible to keep these values in a
    QofQ? So that items (e.g., store locations in my case) with NULL or
    ZERO values for some or all days or months can be charted? Even
    with a ZERO value? I've read everything I can get my hands on
    regarding QofQ, the CAST function, etc., but nothing seems to work.
    Thanks for any help. (FYI, didn't have this problem with CF5. It's
    QofQ could handle NULL or ZERO values without providing an error).
    Gary

    Well, I tried the IsNull function on the 3 SUM() values I was
    calculating in my SELECT statement (on a LEFT OUTER JOIN QUERY),
    and I STILL got another "cannot convert "" to a number" but this
    time the error message was more direct, and pointed me to a DATE
    field in my query, where I was SORTING AND GROUPING either by DAY
    or MONTH (depending on what user selected on form).
    In my QofQ, I'm not just reformating the integer SUM()
    values, but also the date values. So, I applied the IsNull()
    function to the DATE values in my main query. I still kept getting
    errors. But after experimenting ((SQL Server BOL docs doesn't give
    ISNULL() examples for DATE FIELDS, only NUMBER fields), I tried
    putting the dates in SINGLE QUOTES in my IsNull() function, the
    QUERY RAN. Then I wasn't sure WHAT date to enter, e.g., 1/1/1889 or
    1/1/2001, etc.
    Then, I discovered, after experimenting, that you cannot just
    blindly enter ANY date when using IsNull in a date field,
    especially if you are using CFGRAPH to chart the results by day.
    You have to select a date within the date range the user selected,
    so this means using the FORM.DATE (or URL.DATE) value from the
    form. Here's the working example from my SELECT main query:
    SELECT SUM(ISNULL(d.ttldb,0)) AS SumOfDB,
    SUM(ISNULL(d.ttldbv,0)) AS SumOfDBV,
    SUM(ISNULL(d.ttldbi,0)) AS SumOfDBI,
    <CFIF '#url.reptype#' IS "DAILY">
    ISNULL(d.depday, '#url.date1#') AS depday
    <CFELSE>
    month(ISNULL(d.depday, '#url.date2#')) AS TranMonth,
    year(ISNULL(d.depday, '#url.date2#')) AS TranYear
    </CFIF>
    Then I discovered that whatever date was used in the URL.DATE
    field (in my case it would be one of the two date field from the
    form, and depended on whether you coded DATE1 or DATE2, the chart
    would always show ZERO values for that date. So I tried putting the
    IsNull() date values in the GROUP BY and ORDER BY statements, e.g.,
    <CFIF '#url.reptype#' IS "DAILY">
    GROUP BY ISNULL(d.depday, '#url.date1#')
    ORDER BY ISNULL(d.depday, '#url.date1#') DESC
    <CFELSE>
    GROUP BY year(ISNULL(d.depday, '#url.date2#')),
    month(ISNULL(d.depday, '#url.date2#'))
    ORDER BY year(ISNULL(d.depday, '#url.date2#')),
    month(ISNULL(d.depday, '#url.date2#'))
    </CFIF>
    And this worked. The report ran just fine, and the chart
    charted every value correctly.
    I guess you have to learn all the little "quirks" about CF7
    and how it's QofQ and chart programs work. But so far, so good.
    Thank you all for your help. Now I've got to update other old
    CF5 programs that are returning errors when there are null values
    from my LEFT OUTER JOIN queries. Will take some time, but at least
    I know how to do it. Thanks to your help.
    I really appreciate your time and efforts to help with this
    issue.
    Gary

  • How to solve NaN error, while dealing with multiplication of double values

    i am getting NaN error in the program.
    consider this following code
    for (j=0;j<nh;j++)
    sum = 0.0;
    for (i=0;i<ni;i++){ sum = sum + (ai[i] * wi[i][j]) ;}
    //System.out.println(sum);
    ah[j] = sigmoid(sum);
    public static float sigmoid(float x)
    return ((Math.exp(x)- Math.exp(-x)) / (Math.exp(x)+Math.exp(-x)));
    ni = 2500-- no of input nodes;
    nh = 5000 -- no of hidden nodes;
    i am getting problem in calculating the "sum" value. its returning NaN for "sum".
    here a[i] values are around some +/- 0.XXXXXXXX upto 14 digits
    and wi[j][j] values are also +/- 0.XXXXXX upto 14 digits.
    all values are of datatype double.
    i was stucked up with this problem. what i am to do?
    give me suggestions..
    please reply me

    This can occur with double divisions. I wrote a small method that solves this:
         * Set double values that have a value of 'NaN' or 'Infinity' to 0.0. This can happen when dividing double values as they
         * don't cause a DivisionByZeroException.
         * @param value Double value to check.
         * @return Input value with 'NaN' and 'Infinity' set to 0.0.
        static public double resetNaN(final double value, final double resetValue) {
            return (Double.isNaN(value) || Double.isInfinite(value)) ? resetValue : value;
        }//resetNaN()

  • Dealing with exponents for double values...

    Hi all,
    I've been putzing around with the NumberFormat class, as well as the Double api, but I can't seem to find a solution on how to remove exponents from double values.
    For example:
    double x = Double.MIN_VALUE;
    Might return 4.9E-123
    How do I remove the E, or any of those special characters, and just retrieve the exact, unshortened value?

    For example:
    double x = Double.MIN_VALUE;
    Might return 4.9E-123It doesn't return 4.9E-123. It returns a double. If you print it out it will look like that.

  • I am a rookie and need help with max and min values

    Hello all, i am into this intro to java class. my assignment is to write a program that prompts the user for two integers and then prints the sum, difference, average, product , distance (absolute value of the difference) Maximum(largest of the two) and Minimum(smallest fo the two) here is my code so far
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.lang.Math;
    public class Sample4
       public static void main(String[] args) throws IOException
          try // attempt the following
    {           // create the stream to read from
    InputStreamReader istream = new InputStreamReader(System.in);   // create a buffer to hold the stream
    BufferedReader console = new BufferedReader(istream);           // prompt the user
          System.out.println("Enter a number please");              // get input as a string
          String input = console.readLine();                        // convert to an integer
          int num1 = Integer.parseInt(input);
          System.out.println("Enter a number please");              // get input as a string
          String input2 = console.readLine();                       // convert to an integer
          int num2 = Integer.parseInt(input2);
          int sum = num1 + num2;                                    // get the sum of the two inputs
          int difference = num1 - num2;                             // get the difference of the two inputs
          int product = num1 * num2;                                // get the product of the two inputs
          int average = sum / 2;                                    // get the average of the two inputs
          int abs = Math.abs(difference);                           // get the absolute value of the two inputs
              // new section
                 // display the number
          System.out.println("The total sum = " + sum);
          System.out.println("The total difference = " + difference);
           System.out.println("The total product = " + product);
           System.out.println("The total average = " + average);
           System.out.println("The total absolute value = " + abs);
    } // if something breaks, catch the exception
    catch (IOException e)
       System.out.println(e); // displays the exception
       System.exit(1);  // quits the program
    }what will be the right syntax or code to find the MAX and MIN values of two numbers a User Inputs, hope someone can help with this. thank you for your help.

    Thanks alot man, sheesh i do not know why my book
    doesnt give me all the static methods. but i do really
    appreciate your help. peaceA complete list of the java.lang.Math methods can be found at http://java.sun.com/j2se/1.4/docs/api/java/lang/Math.html
    btw,
    max(a, b) == (a > b) ? a : b
    min(a, b) == (a < b) ? a : b

  • Post material master idoc  with class and characteristic values

    Hi,
    I need to post the class and characterstic values of material while posting the material using idoc of basic type matmas05 . Can anyone suggest me the fields and segment details to fill the class, class type and characteristic values in matmas05.
    Note : the class and characteristic values are already created in the system, my purpose is to assign them to material while creating. so please give me the field and segment details in idoc basic type matmas05.
    thanks
    Kiran

    I  try to do the samething. I see the fields E1CUVAL : CU: Characteristic valuation in the structure of MATMAS05 but when I run the IDOC, these fields never appear even they exist for the material.
    Did you find an answer to your question that can help me?

  • Possible bug: Saving array with extended and double precision to spreadshee​t

    If one concatenates a double precision array and an extended precision array with the "build array" vi and then saves using "Write to Spreadsheet File" vi any digits to the right of the decimal place are set to zero in the saved file. This happens regardless of the format signifier input (e.g. %.10f) to the  "Write to Spreadsheet File" vi.
    I am on Vista Ultimate 32 bit and labview 9.0
    This is a possible bug that is easily circumvented by converting to one type before combining arrar to a spreadsheet. Nonetheless, it is a bug and it cost me some time.
    Solved!
    Go to Solution.
    Attachments:
    Spreadsheet save bug.vi ‏9 KB

    Hi JL,
    no, it's not a bug - it's a feature
    Well, if you would look more closely you would recognize the "Save to Spreadsheet" as polymorphic VI. As this polymorphic VI doesn't support EXT numbers internally (it only supports DBL, I64 and String) LabVIEW chooses the instance with most accuracy: I64 (I64 has 64 bits precision, DBL only 53...). So your options are:
    - set the instance to use as DBL (by right-click and "Select type...")
    - make a copy of this VI, save it with a different name and make it support EXT numbers (don't rework the polymorphic VI as you would break compatibility with other LV installations or future revisions)
    And yes, those coercion dots always signal some conversions - you should atleast check what's going on there...
    Message Edited by GerdW on 05-21-2010 10:01 PM
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • VS2013 x64 p/invoke issue with C++ functions returning float or double values to C#

    I originally posted this on the Windows Insiders forum, but I was directed to either TechNet or MSDN as this was deemed too technical. 
    I do understand that Windows 10 is still in preview mode, and VS2013 doesn't officially support it yet, but I just wanted to make a note of this, and ensure it gets fixed  :)  
    The issue:
    I ran across what appears to be a .Net bug in Windows 10.  This issue does NOT appear when using either Windows 7 or Windows 8 Enterprise.  This also does NOT appear when running an x86 build.  This is an x64 specific issue, and occurs in
    both release and debug configurations. 
    If you have a C++ function that looks like this:
    double GetValueDouble()
      return 555.555;
    And on the C# side:
    [DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
    public static extern double GetDoubleValue();
    static class Program
      static int Main(string[] args)
        double val = GetDoubleValue();
        Console.WriteLine("val = {0}", val);
    I'd expect the output to be:
    val = 555.555
    But I actually get something like this:
    val = -2.0608193755203536E+262
    This has been reproduced on two different machines, both running Windows 10. 
    Is this a known bug?  I searched the forums, but didn't find anything relevant.

    I can repro, but only running under the VS2015 preview debugger. Running the console app directly gives the 555.555 value:
    C:\scratch\DoubleRepro\ConsoleMain\bin\x64\Debug>dir
     Volume in drive C has no label.
     Volume Serial Number is C285-B76C
     Directory of C:\scratch\DoubleRepro\ConsoleMain\bin\x64\Debug
    02/18/2015  06:42 PM    <DIR>          .
    02/18/2015  06:42 PM    <DIR>          ..
    02/18/2015  06:45 PM             4,096 ConsoleMain.exe
    02/18/2015  06:37 PM               187 ConsoleMain.exe.config
    02/18/2015  06:45 PM            11,776 ConsoleMain.pdb
    02/18/2015  06:41 PM            45,568 CPP_DLL.dll
                   4 File(s)         61,627 bytes
                   2 Dir(s)  89,595,490,304 bytes free
    C:\scratch\DoubleRepro\ConsoleMain\bin\x64\Debug>ConsoleMain.exe
    val = 555.555
    C:\scratch\DoubleRepro\ConsoleMain\bin\x64\Debug>dumpbin cpp_dll.dll /headers
    Microsoft (R) COFF/PE Dumper Version 11.00.60610.1
    Copyright (C) Microsoft Corporation.  All rights reserved.
    Dump of file cpp_dll.dll
    PE signature found
    File Type: DLL
    FILE HEADER VALUES
                8664 machine (x64)
                   8 number of sections
            54E54D6A time date stamp Wed Feb 18 18:41:46 2015
                   0 file pointer to symbol table
                   0 number of symbols
                  F0 size of optional header
                2022 characteristics
                       Executable
                       Application can handle large (>2GB) addresses
                       DLL
    How about yourself? Does it repro outside of the VS debugger?

  • Transfering elements to new array and doubling values.

    Hi my problem is that I need to ask a user to enter 5 integers that stores them in an array. Transfer them to a new array by doubling the values when trasferred.
    Please help I have 3 errors.
    class arrays
         public static void main (String[] args)
              int numbers[] = new int [5];
              byte array1Size = 0;
              int input = 0;
              char goon = 'y';
                   //create and initialise an array of 5 integers
                   int array1[] = new int [5];
                   // loop and fill each element
                   for (int x = 0; x < array1.length; x++)
                        System.out.println("Enter a number: ");
                        array1[x] = EasyIn.getInt();
                        // Filling array
                        if (array1Size >= array1.length)
                             //Make a new array doubling the values od the integers
                             int array2 [] = new int [2 * array1.length]; // 10 integers
                             //Copying integers
                             System.arrayCopy (array1, 0, array2, 0, array1.length);
                             //Make old reference point to new array
                             array1 = array2;
                        else
                             //normal
                             do
                                  System.out.print("Enter an integer: ");
                                  input = EasyIn.getInt();
                                  anotherArray[anotherArraySize] = input;
                                  anotherArraySize++;
                                  System.out.print ("Another number? Enter Y or N: ");
                                  goon = EasyIn.getChar();
                             }     while(goon = = 'y' | goon = = 'Y');
    the errros >>>
    G:\Java\Practical 7\Practical74.java:33: '.class' expected
                             int array2 [] = new int [2 * array1.length]; // 10 integers
    ^
    G:\Java\Practical 7\Practical74.java:33: not a statement
                             int array2 [] = new int [2 * array1.length]; // 10 integers
    ^
    G:\Java\Practical 7\Practical74.java:41: 'else' without 'if'
                        else
    ^
    3 errors
    Tool completed with exit code 1
    Thanks

    Hi,
    it seems you forgot the curly braces in the if-else statement:
    if (array1Size >= array1.length){
    //Make a new array doubling the values od the integers
    int array2 [] = new int [2 * array1.length]; // 10 integers
    //Copying integers
    System.arrayCopy (array1, 0, array2, 0, array1.length);
    //Make old reference point to new array
    array1 = array2;
    else{
    //normal
    do
    System.out.print("Enter an integer: ");
    input = EasyIn.getInt();
    anotherArray[anotherArraySize] = input;
    anotherArraySize++;
    System.out.print ("Another number? Enter Y or N: ");
    goon = EasyIn.getChar();
    } while(goon = = 'y' | goon = = 'Y');
    }

  • Problem with inheritance and outputting values in toString.

    Hey guys, i'm having a major problem with inheritances.
    What i'm trying to do with my program is to create objects in my demo class. Values are passed to several other objects that each do their own calculations of grades and results and then outputs the result in my toString. I followed step by step the instructions in my book on how to setup the inheritance and such. I can only output everything that was created in my superclass, any other thing that was created in an object that belongs to a subclass does not display in the output at all.
    Even if I change or create new instance variables, I can't figure out for the life of myself how to output the other values.
    Because there's so much code to be splitting on the forums, I zipped my whole project in a RAR. I'll link it here
    http://www.4shared.com/file/ZleBitzP/Assign7.html
    The file to run the program is CourseGradesDemo class, everything else is either a subclass or superclass to some part of the program. After you run CourseGradesDemo, you will see the output, and understand what displays and what stays at 0.0 value. If anyone can help me out with this it would be greatly appreciated
    Thanks in advance.

    Basshunter36 wrote:
    Hey guys, i'm having a major problem with inheritances.
    What i'm trying to do with my program is to create objects in my demo class. Values are passed to several other objects that each do their own calculations of grades and results and then outputs the result in my toString. I followed step by step the instructions in my book on how to setup the inheritance and such. I can only output everything that was created in my superclass, any other thing that was created in an object that belongs to a subclass does not display in the output at all.
    Even if I change or create new instance variables, I can't figure out for the life of myself how to output the other values.No idea what you're talking about. Provide an [url http://sscce.org]SSCCE.
    Because there's so much code to be splitting on the forums, I zipped my whole project in a RAR. I'll link it here
    http://www.4shared.com/file/ZleBitzP/Assign7.html
    Not gonna happen. Provide an [url http://sscce.org]SSCCE. And don't say you can't. You definitely can. You may have to spend an hour building a new program from scratch and getting it to reproduce the problem, but if you can't or won't do that, you'll find few people here willing to bother with it.

  • Problem with dg4msql and table-valued functions

    Have configured dg4msql to connect from my oracle db to ms sql server.
    Am able to do simple SELECTs from ms sql tables like:
    select * from "sys"."procedures"@dg4msql;
    or
    select * from "dbo"."SomeTable"@dg4msql;
    But am unable to do a SELECT from a table-valued function:
    select * from "dbo"."GetData"@dg4msql('param1value');
    or
    select * from "dbo"."GetData"('param1value')@dg4msql;
    In both cases I get:
    ORA-00933: SQL command not properly ended
    It does not like the parameters portion of the query ("('param1value')")
    initdg4msql.ora:
    HS_FDS_CONNECT_INFO=[svr1]//mydb
    HS_FDS_TRACE_LEVEL=OFF
    HS_FDS_PROC_IS_FUNCT=TRUE
    HS_FDS_RESULTSET_SUPPORT=TRUE
    Have tried the other set of params:
    HS_FDS_PROC_IS_FUNCT=FALSE
    HS_FDS_RESULTSET_SUPPORT=TRUE
    Same story. After changing the init*** file have bounced both Listeners (DB and Gateway), reconnected, and re-run the query.
    Have I missed something?
    Any help is greatly appreciated!

    Sorry, but for me it looks you did not get the problem.
    Oracle® Database Gateway for SQL Server User's Guide,:
    11g Release 2 (11.2)
    Part Number E12069-02
    *2 SQL Server Gateway Features and Restriction*
    Result Sets and Stored Procedures
    The Oracle Database Gateway for SQL Server provides support for stored procedures which return result sets.
    By default, all stored procedures and functions do not return a result set to the user. To enable result sets, set the HS_FDS_RESULTSET_SUPPORT parameter value to TRUE.
    PL/SQL Program Fetching from Result Sets in Sequential Mode
    -- Execute procedure
    out_arg := null;
    refcurproc@MSQL('Hello World', out_arg, rc1);
    Somewhere in this forum I've seen a message that the syntax "SELECT ... FROM sp@db(param1, param2)" works.
    Anyway, even with the PL/SQL block the error message is the same - ORA-00933 "SQL command not properly ended"
    and the cursor (* in SQL*PLUS) is put just at the first bracket.
    Edited by: user636213 on Aug 10, 2012 5:17 AM

Maybe you are looking for