These are the only answers I could not find can anyone help me out please

  public class TestA {
   public static void main( String args[] )
   {
      int x = 2, y = 20, counter = 0;

      for ( int j = y % x; j < 100; j += ( y / x ) ) {
         counter++;   
      }
   }
}

public class TestB {
   public static void main(String args[])
   {
      int counter = 0;

      for ( int j = 10; j > 0; --j ) {
         ++counter;   
      }
   }
}

Which of the following statements is true ( circle all that apply, or none )?
a.The value of counter will be the different at the end of each for loop for each class.
b.The value of j will be the same for each loop for all iterations
c.Both (a) and (b) are true.
d.Neither (a) nor (b) is true.

-----------------------------------------------------------------------------------
. Consider the code segment below.

if ( gender == 1 )
   if ( age >= 65 )
      ++seniorFemales;

This segment is equivalent to which of the following ( circle all that apply, or none )?
a.   if ( gender == 1 || age >= 65 )
   ++seniorFemales;
b.   if ( gender == 1 && age >= 65 )
   ++seniorFemales; 
c.   if ( gender == 1 AND age >= 65 )
   ++seniorFemales; 
d.   if ( gender == 1 OR age >= 65 )
   ++seniorFemales; 

----------------------------------------------------------------------------------------------------

Consider the following Java statements:

int x = 9;
double y = 5.3;
result = calculateValue( x, y );

Which of the following statements is true ( circle all that apply, or none )?
A. The method call operator is ().
B x and y are parameters.
C. Copies of x and y are passed to the method calculateValue().
D. x and y are arguments.

a. None of the statements are true.
b. B and D are true.
c. B is false.
d. All of the statements are true.

Hi Ryano24,

We're not allowed to just give you the answers but we can try to point you in the right direction. What do you think the answers are? Take an educated guess and we will let you know where you've gone wrong.

Cheers,
darkagn

If you look at the 2nd question,

if ( gender == 1 )
     if ( age >= 65 )
         ++seniorFemales;

is the same as saying

if ( gender == 1 ){
      if ( age >= 65 ){
             ++seniorFemales;
      }
}

if and else statements don't require { } if their statements only consist of a single line, so what do you think the answer is?


and for the third question:
Think of the difference between
result = calculateValue( x, y ); and
result = calulateVales;
It looks to me like one is calling a method and the other is assigning something to something else.

Also, what's happening with x and y when you call calculateValue(x, y) if calcualteValue() looks like this:

public void calculateValue(int u, int v){
     ......
}

How does x and y turn into u and v?

If you can figure those questions out, you've already got 2 out of 3..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.