Can someone help me with these Java Questions.?

I really need help!!!

1. What should the first line of the "main" part of a program look like?

2. How many times will the for loop below execute?

3. What will the for loop below print?

4. Why does the last println print out i = 11 ?

int i = 0;

for( i = 0; i<= 10; i++)

{

System.out.println(" i = " + i);

}

System.out.println('and finally");

System.out.println(" i = " + i);

5. What does each number represent in the statement

fillRect(50, 25, 250, 255); ?

6. What is the difference between the following variable types :

int, double, boolean, char, String ?

7. Re-write the following for loop as a while loop:

for( int i = 0; i < 5; i++ )

{

System.out.println(“blah, blah, blah”);

}

8. Fill in the blanks in the following sentences:

"Computer programmers start counting from __________ . "

"When processing an array, use a ________ to process __________ element at a _________."

9. For the array

int[] array2 = { 21, 32, 43, 54 };

What are the values of array2[0] and array[2] ?

Consider the following code:

if( x > 0 )

System.out.println("Mr Gongwer is awesome"):

else if(x < 0)

System.out.println("Mr Gongwer is TOTALLY awesome");

else

system.out.println("Mr Gongwer is SUPER awesome");

10. What will print if x = 0?

11. When you have nested loops, which loop gets executed more times, the inside or the outside loop? and why?

3 Answers

Relevance
  • McFate
    Lv 7
    8 years ago
    Favorite Answer

    1. public static void main( String[] args )

    2. 11 times (i=0 through i=10, inclusive)

    3. I assume you can work this out from the above and below answers

    4. The loop executes until the test condition (i <= 10) fails. It first fails when i=11.

    This stuff is all pretty simple. Also you should either know this (if you've done any programming at all) or try to gain the experience of figuring it out yourself.

    @M

  • 8 years ago

    1. public static void main(String[] args) {

    2. 11

    3. i = 0 ... 1 = 10

    4. because of for loop will stop when i = 11

    5. the x coordinate of the rectangle to be filled.

    the y coordinate of the rectangle to be filled.

    the width of the rectangle to be filled.

    the height of the rectangle to be filled.

    6. http://docs.oracle.com/javase/tutorial/java/nutsan...

    7. int i = 0;

    while (i <= 5) {

    i++;

    System.out.println(“blah, blah, blah”);

    }

    8. "Computer programmers start counting from __0________ . "

    "When processing an array, use a ___0_____ to process _____first_____ element at a _____??____."

    9. 21, 43

    10. Mr Gongwer is SUPER awesome

    11. inside, because it gets executed fully in every pass of the outside loop

  • Red
    Lv 6
    8 years ago

    If you don't understand the answers to these, you really need to be talking to your teacher about how little you're actually understanding from the class; not on here trying to get someone to do your homework for you.

Still have questions? Get your answers by asking now.