Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

I fial at java

Name: some retard 2008-03-20 11:53

   6. The following for loop will print out the first 20 squares. Convert the for loop into a while loop.

      for(int i = 1; i <= 20; i++)
         System.out.println(i + " squared is " + i * i);



While ( I <= 20) {
  System.out.println (i + “squared is” + i * i);
  i++
       }



   7. Explain the difference between a while statement and a do-while.

The while statement continually executes a block of statements while a particular condition is true which it checks first. The difference is that do-while evaluates its expression at the bottom of the loop instead of the top



   8. Given:

      final double rate = 6.25;
      char             pass =  'P';


      True or false, the following statements are correct. If false, you must Explain!

      a)    rate  =  9.35;


False. Because the expression ‘final’ was used, rate cannot be assigned a new value. Thus it remains with its first value 6.25

      b)  pass  =  "pass";


we would have to specify that the code is a string for this to work

   9. What is the output?

      int [] X = {22,44,88};
      int [] Y = {11,33,55};
      Y = X;
      System.out.println( Y[0] );
      System.out.println( X[ X.length � 1] );

 22 and 44


is this all correct?

Name: Anonymous 2008-03-20 11:55

map (^2) [1..20]

Name: Anonymous 2008-03-20 11:55

and I fail so hard I spelled fail wrong in my opening post

Name: Anonymous 2008-03-20 12:03

Tell me about this � operator.

Name: Anonymous 2008-03-20 12:06

hmm thats weird. for some reason it pasted as �. the correct thing is

int [] X = {22,44,88};
int [] Y = {11,33,55};
Y = X;
System.out.println( Y[0] );
System.out.println( X[ X.length - 1] );

Name: Anonymous 2008-03-20 12:34

is this all correct?
actually no.

Name: Anonymous 2008-03-20 12:39

>>6
I guess my mistake is question 9

Name: Anonymous 2008-03-20 12:41

>>1
while first tests the expression then enters its body, do/while first enters the body and then tests the expression

Name: Anonymous 2008-03-20 13:16

>>7
6 and 9

Name: Anonymous 2008-03-20 13:42

number 6 should be 22 and 88

Name: Anonymous 2008-03-20 13:53

>>4
It's the binary conditional operator. In this case if X.length is true, it evaluates to 1, otherwise it evaluates to false.

Name: Anonymous 2008-03-20 14:36

6. Incomplete.
7. Could be clearer.
8a. Correct.
8b. Which 'code'? Clarify.
9. Incorrect.

I would probably give you half a point per question.

Name: Anonymous 2008-03-20 16:01

>>1
Don't write your posts in MS Word.

Name: Anonymous 2008-03-20 16:10

written using msword-mode

Name: Anonymous 2010-11-15 3:09

Don't change these.
Name: Email:
Entire Thread Thread List