Question

1. What output will be produced by the following code? int extra = -37; if (extra...

1. What output will be produced by the following code?

int extra = -37;
if (extra < 0)
 System.out.println("small");
else if (extra == 0)
 System.out.println("medium");
else
 System.out.println("large")

a. large

b. medium

c. small

d. nothing

Homework Answers

Answer #1

answer is c) small,because extra is -37 first it checks condition in "if" and checks extra<0 if it's true and print small.

extra -37<0 so it prints small and do not go to else if and else.so program ends

program is:

class y{
   public static void main(String args[]){
   int extra = -37;
   if (extra < 0)
        System.out.println("small");
   else if (extra == 0)
        System.out.println("medium");
   else
       System.out.println("large");   // here if semicolon missing it gives error.
   }
}

Output:

small

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(C++ program) Use the code segment below to answer the two questions that follow. … int...
(C++ program) Use the code segment below to answer the two questions that follow. … int size = 0; cout << “Enter size: “; cin >> size; int sizeCode = size / 10; if (sizeCode == 0)    cout << “extra small”; else if(sizeCode == 1 )    cout << “small”; else if (sizeCode == 2)    cout << “medium”; else if (sizeCode == 3)    cout << “large”; else    cout << “extra large”; //end if … What would...
what output is produced by the following code and explain how it works. public class A...
what output is produced by the following code and explain how it works. public class A { int a = 1; int b = 2; public int getSum(int a, int b) {     this.a+=a;     this.b+=b;     return this.a + this.b; } } public class B extends A { int a = 3; int b = 4; public int getSum(int a, int b) {     this.b=a;     super.b=b+b;     return super.a+this.b; } } public class q2 { public static void...
What will be the output of the following C code segment? int u = 0x2; int...
What will be the output of the following C code segment? int u = 0x2; int v = 0x35; if (u && v) printf(“Great!! \n”); else printf(“Fantastic!! \n”);
1. What is the output of the following code fragment? (All variables are of type int.)...
1. What is the output of the following code fragment? (All variables are of type int.) limit = 8; cout << 'H'; for (loopCount = 10; loopCount <= limit; loopCount++) cout << 'E'; cout << "LP"); 2. What is the output of the following code fragment if the input value is 4? (Be careful here.) int num; int alpha = 10; cin >> num; switch (num) { case 3 : alpha++; case 4 : alpha = alpha + 2; case...
3. What will be the value of w after the following section of code executes: int...
3. What will be the value of w after the following section of code executes: int w = 4, q = 3; if (q > 5)       if (w == 7)           w == 3;       else            if (w > 3)               w = 1;            else               w = 0; A.0            B.1              C.2          D.3 4. What will be the value of b after the following section of code executes: int a = 4, b = 0; if (a...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); Second question Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same...
//1. Write out the output for eaching of following: /* Consider this function. void myMethod( int...
//1. Write out the output for eaching of following: /* Consider this function. void myMethod( int counter) { if(counter == 0) return; else { System.out.println(""+counter); myMethod(--counter); return; } }
1.    Given the following segment of code: (If there is nothing output, write None.) int x;...
1.    Given the following segment of code: (If there is nothing output, write None.) int x; int y; cin >> x; cin >> y; while (x > y) {     x -= 3;     cout << x << " "; } cout << endl;        a.    What are the output and final values of x and y when the input is 10 for x and 0 for y? [2, 2, 2]               Output                                                                                                                                                                                                    x = ______________                                                                                                                                                                                                   ...
What is "missing part" in the piece of code below to produce the following output 012345...
What is "missing part" in the piece of code below to produce the following output 012345 12345 2345 345 45 5 String base = "012345"; int count = 0; while (count <= 5) {   String tmp = ______________; System.out.println(tmp); count++;    } a) base.substring(count,6) b) base.substring(1,count+1) c) base.substring(0, count) D)base.substring(count+1) e)  base.substring(count)
What is the output of the following code segment? public class Exception { ... static int...
What is the output of the following code segment? public class Exception { ... static int divider(int x, int y) { try { return x/y; } catch (ArrayIndexOutOfBoundsException a) { System.out.print("A"); return 1; } } static int computer(int x, int y) { try { return divider(x,y); } catch (NullPointerException b) { System.out.print("B"); } return 2; } public static void main(String args[]){ try { int i = computer (100, 0); } catch (ArithmeticException c) { System.out.print("C"); } } } ABC A...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT