Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: values of variables changing despite not modifying them

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default values of variables changing despite not modifying them

    Hi,

    My problem is in the following code. The code with *** is changing the values of sensors.get(i).getTemperature and/or sensors.get(j).getTemperature. If I leave this line out, the temperatures appear normal. With that line, they take unexpected large negative values. Anyone know what's going on and have a possible solution? Thanks


     public static boolean verifyAssessor( Assessor assessor, List<Sensor> sensors)
        {
        boolean result = true;
     
        int i,j;
        int consistentWith = 0;
        int functioningSensors = 0;
     
     
        for(i=0;i<sensors.size();i++){
          consistentWith = 0;
          for(j=0;j<sensors.size();j++){
            if(i!=j){
              if(Math.abs(sensors.get(i).getTemperature()-sensors.get(j).getTemperature())/sensors.get(i).getTemperature() <=
                  Assessor.ERROR && sensors.get(i).getTemperature()!=-1 && sensors.get(j).getTemperature()!=-1){
                 consistentWith ++; //***
              }
            }
          }
          //Count the number of functioning sensors
          if(consistentWith>=2){
            functioningSensors ++;
          }
        }
    Last edited by AndyKow; October 9th, 2011 at 01:06 PM.


  2. #2
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: values of variables changing despite not modifying them

    Can you put your format your Code Correctly?

    Edit Post > "#" Symbol > Copy & Paste Code into Tags
    Simplicity calls for Complexity. Think about it.

Similar Threads

  1. Character Values Inside of Number Values
    By bgroenks96 in forum Java Theory & Questions
    Replies: 4
    Last Post: October 2nd, 2011, 08:27 PM
  2. Modifying a complicated object with dialog boxes
    By hunter555 in forum Java Theory & Questions
    Replies: 7
    Last Post: January 27th, 2011, 02:02 PM
  3. Changing Array variables from different classes
    By smellyhole85 in forum Collections and Generics
    Replies: 6
    Last Post: December 9th, 2010, 02:18 PM
  4. Interating through an ArrayOrderedList and modifying elements within
    By xecure in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 26th, 2010, 10:15 PM
  5. Java Question Need Help Restarting the Values of Variables from Random Numbers So Out
    By JavaStudent1990 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2010, 02:25 PM