Results 1 to 4 of 4
  1. #1
    NixasMuraki is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default Rounding decimal error

    I am trying to round these decimals, but I get the error unexpected type: found: value required: variable. (First of all I don't know how you can round a variable, but that's not the point) I just want to round, this shouldn't be rocket science and I probably made some stupid mistake, but I would really appreciate it if someone pointed me in the right direction, and by the right direction I mean directly tell me what I'm doing wrong. Arigato gozaimasu (thank you) in advance.
    import java.io.*;
    import java.util.*;
    import java.util.Random.*;
    public class HA2
    {
    public static void main(String[] args)
    {

    //let R be any real rational number
    //if 0=0 infinite solutions if 0=anything else no solution
    //first problem will be Infinite or No Solutions with Elimination
    Random generator=new Random();//use nextGaussian() to create random positive and negative ints
    double R1=(generator.nextGaussian()*100);//makes a random real number
    double R2=generator.nextGaussian();
    double R3=generator.nextGaussian();
    double R4=generator.nextGaussian();
    double R5=generator.nextGaussian();
    double R6=generator.nextGaussian();
    Math.round((R1*100)/100)=R1;//this is where error occurs
    Math.round(100*R2)/(100)=R2;
    Math.round(100*R3)/(100)=R3;
    Math.round(100*R4)/(100)=R4;
    Math.round(100*R5)/(100)=R5;
    Math.round(100*R6)/(100)=R6
    ;

    System.out.println("Use elimination to determine whether this will have infinite or no solutions\n " +R1+"x+"+R2+"y="+R3+"\n" +R4+"x+"+R5+"y="+R6);

    }
    }

  2. #2
    Zman3359's Avatar
    Zman3359 is offline Member
    Join Date
    Jan 2011
    Posts
    42
    Rep Power
    0

    Default

    The problem is your trying to assign a value to a method. When you type "Math.round(100*R2)/(100)=R2;" Java thinks your trying to set Math.round() (which is a method) to the double value of R2 and you can't do this because methods don't hold values. This is what causes the error you are getting. Try this instead. Also code blocks make your code easier to read :)
    Java Code:
    R1 = Math.round((R1*100)/100);
    R2 = Math.round(100*R2)/(100);
    R3 = Math.round(100*R3)/(100);
    R4 = Math.round(100*R4)/(100);
    R5 = Math.round(100*R5)/(100);
    R6 = Math.round(100*R6)/(100);

  3. #3
    NixasMuraki is offline Member
    Join Date
    Jan 2011
    Posts
    11
    Rep Power
    0

    Default

    *facepalm* DUH ...thanks I guess I'm just temporarily brain dead :/

  4. #4
    Zman3359's Avatar
    Zman3359 is offline Member
    Join Date
    Jan 2011
    Posts
    42
    Rep Power
    0

    Default

    No problem. Everyone has brain farts, and it really doesn't help that some of Java's error messages can be somewhat cryptic.

Similar Threads

  1. Compile Error (decimal rounding attempt)
    By mylosol in forum New To Java
    Replies: 2
    Last Post: 05-08-2011, 11:13 PM
  2. Replies: 3
    Last Post: 01-01-2011, 02:36 AM
  3. Decimal to binary, octal to decimal
    By matejm1994 in forum New To Java
    Replies: 3
    Last Post: 12-26-2010, 09:59 AM
  4. rounding double to two decimal places
    By javaMike in forum Advanced Java
    Replies: 15
    Last Post: 03-10-2010, 12:04 AM
  5. java division and decimal error
    By heartysnowy in forum New To Java
    Replies: 5
    Last Post: 10-07-2009, 04:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •