Question

JAVA 5) What is the output of the following code? int a = 70; boolean b...

JAVA

5) What is the output of the following code?

int a = 70;
boolean b = false;

if(a >= 70) {
   System.out.print(1);
   
   if(b==true) {
      System.out.print(2);
   }

} else {
   System.out.print(3);

   if(b==false) {
      System.out.print(4);
   }

}
System.out.print(5);

6) What is the output of the code above using these initial values?

int a = 43;
boolean b = false;

7) The following method is SYNTACTICALLY correct (meaning it will compile). True or false?

public boolean method() {
   int value = 5;
   if(value > 0) {
      return true;
   }
}

8) The following method is SYNTACTICALLY correct (meaning it will compile). True or false?

public boolean method() {
   int value = 5;
   if(value > 0) {
      return true;
   } else {
      return false;
   }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 5:15
as the a>=70 is true and b is false

Answer 6:345
as the a>=70 is false and b is false so it prints 3 and 4

Answer 7:False
it is missing the return statement in false case
Answer 8: True
it will compile

Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
JAVA 5) What is the output of the following code? int a = 70; boolean b...
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
  • What will be the output of the following Java code? class Output { public static void...

    What will be the output of the following Java code? class Output { public static void main(String args[]) { boolean a = true; boolean b = false; boolean c = a ^ b; System.out.println(!c); } } a) 0 b) 1 c) false d) true

  • I need a java flowchart for the following code: import java.util.*; public class Main {   ...

    I need a java flowchart for the following code: import java.util.*; public class Main {    public static void main(String[] args) {    Scanner sc=new Scanner(System.in);           System.out.print("Enter the input size: ");        int n=sc.nextInt();        int arr[]=new int[n];        System.out.print("Enter the sequence: ");        for(int i=0;i<n;i++)        arr[i]=sc.nextInt();        if(isConsecutiveFour(arr))        {        System.out.print("yes the array contain consecutive number:");        for(int i=0;i<n;i++)        System.out.print(arr[i]+" ");       ...

  • QUESTION 1 What is the output of the following code snippet? int main() { bool attendance...

    QUESTION 1 What is the output of the following code snippet? int main() { bool attendance = false; string str = "Unknown"; attendance = !(attendance); if (!attendance) { str = "False"; } if (attendance) { attendance = false; } if (attendance) { str = "True"; } else { str = "Maybe"; } cout << str << endl; return 0; } False True Unknown Maybe QUESTION 2 What is the output of the following code snippet? #include <iostream> #include <string> using...

  • 1. What is output by the following code? String s0 = "Java"; int i1 = s0.indexOf('a');...

    1. What is output by the following code? String s0 = "Java"; int i1 = s0.indexOf('a'); int i2 = s0.indexOf('a', i1); int i3 = s0.indexOf('a', i1 + 1); System.out.print(i1 + " " + i2 + " " + i3); 2. What is output by the following code? String s1 = "Java"; String s2 = ""; for (int i = 0; i < s1.length(); i++) { s2 += s1; } System.out.print(s2);

  • Question 11 (3 points) What does the following recursive method determine? public boolean question 16(int[]a, int[]...

    Question 11 (3 points) What does the following recursive method determine? public boolean question 16(int[]a, int[] b. intj) { if (j == 2.length) return false; else if ( == b.length) return true; else return question 16(2, b.j+1): 3 returns true if b contains less elements than a, false otherwise returns true if b contains more elements than a, false otherwise returns true if a and bare equal in size, false otherwise returns true if a's element value is larger than...

  • Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks...

    Java Homework Help. Can someone please fix my code and have my program compile correctly? Thanks for the help. Specifications: The class should have an int field named monthNumber that holds the number of the month. For example, January would be 1, February would be 2, and so forth. In addition, provide the following methods. A no- arg constructor that sets the monthNumber field to 1. A constructor that accepts the number of the month as an argument. It should...

  • In Java, Assume we have these two methods. public static boolean allAreEqual(int n1, int n2, int...

    In Java, Assume we have these two methods. public static boolean allAreEqual(int n1, int n2, int n3) { return n1 == n2 && n2 == n3; } public static boolean mystery(int n1, int n2, int n3) { return !allAreEqual(n1, n2, n3) && (n1 == n2 || n1 == n3 || n2 == n3); } Part 1: What value will be returned by the following method calls? mystery(5, 5, 5) mystery(5, 5, 1) Part 2: What does the mystery method do...

  • I am given an input file, P1input.txt and I have to write code to find the...

    I am given an input file, P1input.txt and I have to write code to find the min and max, as well as prime and perfect numbers from the input file. P1input.txt contains a hundred integers. Why doesn't my code compile properly to show me all the numbers? It just stops and displays usage: C:\> java Project1 P1input.txt 1 30 import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 {    public static...

  • Write Junit Test for the following class below: public class Turn {    private int turnScore;    private Dice dice;    private boolean isSkunk;    private boolean isDoubleSkunk;    public Turn()    {...

    Write Junit Test for the following class below: public class Turn {    private int turnScore;    private Dice dice;    private boolean isSkunk;    private boolean isDoubleSkunk;    public Turn()    {        dice = new Dice();    }    public Turn(Dice dice) {        this.dice = dice;    }       public void turnRoll()    {        dice.roll();        if (dice.getDie1Value() == 1 || dice.getDie2Value() == 1 && dice.getLastRoll() != 2)        {            turnScore = 0;            isSkunk = true;        }        else if (dice.getLastRoll() == 2)        {            turnScore = 0;            isDoubleSkunk = true; }        else        {           ...

  • Need help with this java code supposed to be a military time clock, but I need...

    Need help with this java code supposed to be a military time clock, but I need help creating the driver to test and run the clock. I also need help making the clock dynamic. public class Clock { private int hr; //store hours private int min; //store minutes private int sec; //store seconds public Clock () { setTime (0, 0, 0); } public Clock (int hours, intminutes, int seconds) { setTime (hours, minutes, seconds); } public void setTime (int hours,int...

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