Question

What is the Java output? Part One: class Driver { public static void main(String[] args) {...

What is the Java output?

Part One:

class Driver {
  public static void main(String[] args) {
    int a = 5;
    int b = 3;

    if (a < b || a * 2 < b)
      System.out.print(a - b);

    System.out.print(b + a);
  }
}

Part Two:

class Driver {
  public static void main(String[] args) {
    int a = 5;
    int b = 8;

    if (a < b)
      if (a * 2 < b)
        System.out.print("foo");
      else
        System.out.print("bar");
    else
      System.out.print("buz");
  }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

part one:

class Driver {
public static void main(String[] args)
{
int a = 5; int b = 3;
if (a < b || a * 2 < b) //5<3 || 5*2<3 => false || false => a-b not executed
System.out.print(a - b);
  
System.out.print(b + a);
  
}
  
}

output:

1.li Result $javac Driver.java $java -Xmx128M -Xms16M Driver

part two:

public class Driver {
public static void main(String[] args)
{
int a = 5; int b = 8;
if (a < b) //5<8 true
if (a * 2 < b) //5*2<8 => false so else executed
System.out.print("foo");
else System.out.print("bar");
else System.out.print("buz");
  
}
  
}

I.l. Result $javac Driver.java $java -Xmx128M -Xms16M Driver bar

Output:

Add a comment
Know the answer?
Add Answer to:
What is the Java output? Part One: class Driver { public static void main(String[] args) {...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT