Question

Can you please help with the Java quesitons below. Thanks. What is most true about ONE...

Can you please help with the Java quesitons below. Thanks.

What is most true about ONE execution of this code? Explain your reasoning to support the correct answer, and also explain why the other answers aren’t correct.

int diffValue = Math.abs(topAv – botAv);
if (diffValue < 10)
  topP.setColor(Color.WHITE);   // Section A
else if (diffValue < 50)
  topP.setColor(Color.GREY);    // Section B
else
   topP.setColor(Color.BLACK);    // Section C

A. Sections A and B may both be executed, but then C can’t be executed.
B. If Section A is executed, then neither Section B nor C can be.
C. All sections can be executed for a single diffValue
D. It’s possible no section is executed for a given diffValue

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Option. A is correct bcoz if section A and B is executed then else statement cannot be executed....... For ex for diffValue=9 condition in if statement as well as in if- else statement both will be true hence both section A and B will be executed. But C will not.

Option B is incorrect bcoz for diffValue =9 both section A and B will be executed.

Option C is incorrect bcoz all sections can not executed for a single value of diffValue. If diffValue = 51 then only section C is executed.

Option D is also incorrect one of all three statement has to be executed for a single value of diffValue. For diffValue >=10 and <50 only statement B will be executed... For diffValue>50 section C is executed and for diffValue <10 both A and B is executed.

Add a comment
Know the answer?
Add Answer to:
Can you please help with the Java quesitons below. Thanks. What is most true about ONE...
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
  • Java 1. Can you explain it how it will be printed step by step? Thanks!! What...

    Java 1. Can you explain it how it will be printed step by step? Thanks!! What is printed by the following? for (int i=1; i<4; i++) { for (char c=’a’; c<=’c’; c++) { if (i%2==0) { i++; System.out.println(i + " " + c); } else { c++; System.out.println(c + " " + i); } } } 2. Is there a compiler error in this code? If so, what is it? If not, what’s printed? Is there a compiler error in...

  • 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...

  • please help me on 12 106 Java Concepts Advanced Placement CS Study Guide 3 12. Consider...

    please help me on 12 106 Java Concepts Advanced Placement CS Study Guide 3 12. Consider the following code segment. int count = 0; for (int x = 0; x< 3; x++) for (int y = x; y < 3; y++) for (int z - y: z < 3; 2++) count++; What is the value of count after the code segment is executed? a 81 b. 27 JOHNNNN mshe thote c. 10x d. 9 e, 6 13. Each segment of...

  • Java will be printed 10. can you explain step by step why? public class WhatsPrinted2 {...

    Java will be printed 10. can you explain step by step why? public class WhatsPrinted2 { public static void whatHappens(int A[]) { int []B = new int[A.length]; for (int i=0; i<A.length; i++) { B[i]=A[i]*2; } A=B; } public static void main(String args[]) { int A[] = {10,20,30}; whatHappens(A); System.out.println(A[0]); } } will print 10. explain how it's works. Thanks public class WhatsPrinted3 { public static int[] whatHappens(int A[]) { int []B = new int[A.length]; for (int i=0; i<A.length; i++) {...

  • Modify Java Code below: - Remove Button Try the Number -Instead of Try the Number button...

    Modify Java Code below: - Remove Button Try the Number -Instead of Try the Number button just hit enter on keyboard to try number -Remove Button Quit import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; // Main Class public class GuessGame extends JFrame { // Declare class variables private static final long serialVersionUID = 1L; public static Object prompt1; private JTextField userInput; private JLabel comment = new JLabel(" "); private JLabel comment2 = new JLabel(" "); private int...

  • It's been too long since I have done any Java programming. Can anyone help me with...

    It's been too long since I have done any Java programming. Can anyone help me with this one? Thank you 6.5 Write the declaration for a class named C that declares: (1) a private int instance variable named mX; (2) a private int class variable named mY initialized to 0; (3) a private int class constant named A which is equivalent to 100; (4) a public int class constant named B which is equivalent to 200; (5) public accessor and...

  • Please help to resolve my error. This Java code is supposed to evaluate one line equation...

    Please help to resolve my error. This Java code is supposed to evaluate one line equation of the form X Operator =Z where X is any name of a variable and Y and Z are integers By user in equation solver window. Currently the code executes expressions such as Y Operator(+,-,*,/) Z package Equations; /** * This program evaluates arithmetic expressions */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.StringTokenizer; public class EquationSolver extends JFrame implements ActionListener { private JTextField...

  • can anyone please help me with these. Please help on 7,8 and 9. Thanks! Principles of...

    can anyone please help me with these. Please help on 7,8 and 9. Thanks! Principles of Chemistry Lab I Montgomery College, Rockville Salts 6. What is hydrolysis? A tupe c reochon +no preakS tne pand ot a morccue wit tne usc ct woter. Complete the table below. Include states of matter. Provide the correct reaction a. salt 7. row Reactive ion Write the equation for the reaction of the ion with water (omit spectator ions). Use the correct reaction arrow....

  • Below, you can find the description of your labwork for today. You can also find the...

    Below, you can find the description of your labwork for today. You can also find the expected output of this code in the Application Walkthrough section. You are going to improve your existing Money & Stock Trading Platform on previous week’s labwork by incorporating Collections. In previous labworks, you have used arrays for holding Customer and Item objects. For this labwork you need to use ArrayList for holding these objects. So, rather than defining Customer[] array, you need to define...

  • [Viscosity Questions] about chemistry: (multiple choice about viscosity) Please help. Thanks!! Explain each one thanks! 1....

    [Viscosity Questions] about chemistry: (multiple choice about viscosity) Please help. Thanks!! Explain each one thanks! 1. A fluid is considered "Newtonian" if: a) it experience laminar flow b) η is independent of the velocity gradient c) η is a constant d) the shearing force is exerted in the direction of the flow e) all of the above 2. The viscosity η is a function of: a) temperature b) Pressure c) composition d) volume e) a, b, and c are correct...

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