Question

1) Copy and paste the code below into your IDE, and then answer the question. if...

1) Copy and paste the code below into your IDE, and then answer the question.

if (false) {
    System.out.println("Hello");
}

What happens and why?

A) Hello is not displayed because the if statement is false

B) "Hello" is displayed even if the if statement is false because the semicolon is cutting it off from its body

C) Program does not run due to a compiler error ie semicolon

D) "Hello" is displayed since the expression in the if statement registers true

2) What is the value of x?

y = true;
m = false;
x = (!y && m) || m;

A) True

B) False

3) Which if statement executes if the variable y is divisible by 6?

A) if (y % 6 ==0)

B) if (y % 5 == 0)

C) if (y % 5 == 1)

D) if (y / 6 == 1)

E) if (y % 6)

4) A program needs to save a customer's name, age, and price total. What would be three appropriate variable data types and names? Pay attention to naming conventions as well.

A) String name, int age, double PRICETotal

B) String name, int age, double priceTotal

C) int name, int age, double priceTotal

D) String name, double age, double priceTotal

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

Qtn 1 - The correct answer is A) Hello is not displayed because the if statement is false

The if statement executes it's block only if the condition provided evaluates to True. In this case since it is False, it will not execute its block and hence hello will not be displayed

Qtn 2 - The correct answer is B) False

The expression for x is (!y && m) || m

Substituting the values for y and m, we get

--> (!true && false) || false

--> (false && false) || false

--> false || false

--> false

Qtn 3 - The correct answers is A) if (y % 6 ==0)

The % (modulus) operator is used to get the remainder of a division

Since y is divisible by 6 , the remained of dividing y by 6 should be 0. i.e y % 6 should be 0

Thus if y is divisible by 6 then y%6==0 and since the condition is true , that if statement will be executed

Qtn 4 - The correct answer is B) String name, int age, double priceTotal

Since the name of a person cannot include numbers, we use a String datatype for it. Hence String name

Since age will be a number (eg. 12, 25 etc) we use an integer (int) datatype.

Since total price can be floating point value (eg, 400.5 , 506.75 ) we have to use double

Also the naming convention followed should be camel-case (each word or abbreviation in the middle of the phrase begins with a capital letter, with no intervening spaces or punctuation)

Add a comment
Know the answer?
Add Answer to:
1) Copy and paste the code below into your IDE, and then answer the question. if...
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
  • QUESTION 3 Assume x = 4 and y = 5, which of the following is true?...

    QUESTION 3 Assume x = 4 and y = 5, which of the following is true? x < 5 || y < 5 x > 5 || y > 5 x < 5 && y < 5 x > 5 && y > 5 QUESTION 14 Which of the following statements are the same? (A) x -= x + 4 (B) x = x + 4 - x (C) x = x - (x + 4) (A) and (B) are...

  • JAVA QUESTION 1 The value returned by a value-returning method can be saved for further calculation...

    JAVA QUESTION 1 The value returned by a value-returning method can be saved for further calculation in the program. True False QUESTION 2 To use a predefined method you must know the code in the body of the method. True False QUESTION 3 A formal parameter is a variable declared in the method heading (ie. it's signature). True False QUESTION 4 A local identifier is an identifier that is declared within a method or block and that is visible only...

  • 1-Is it possible to run a program without a main() function? Yes No 2- How many...

    1-Is it possible to run a program without a main() function? Yes No 2- How many main() functions can one have in a program? 2 This depends on what compiler you use. As many as you like 1 3- What does the following code fragment leave in x? char a = 'A'; int x = sizeof (a); 1 Depends on what compiler you use. 4 2 4- True or false: In a C program I can have two functions with...

  • Name: True/False & Multiple Choice (2 points each) (True / False ) 2 A char literal...

    Name: True/False & Multiple Choice (2 points each) (True / False ) 2 A char literal '2', a string literal "2", and the numeric literal 2 are identical and stored the same way though they are different types. 3 Since comments do not affect the program execution, you don't need to have it at all. 4. After the following statements are executed, the value of the variable rem is 3. 1. A preprocessor directive line starts with a pound sign...

  • e fellowing class declaration to answer the questionist below class WeatherStation public emp, double wind, string...

    e fellowing class declaration to answer the questionist below class WeatherStation public emp, double wind, string wind dir, double prediplk void void void int Winda int getTempo double getWindSpeed) : string getWind Direction): double getPrecipitation: void setTemp(int t void setWindData(double w, string dir): void setPrecip(double pl printTempO private int temperature double windSpeed, precipitation string windDir method 14) 14) Refer to the class declaration above. Which of the following methods is an accessor A) int WindChillo: C) WeatherStation: B) void setPrecipO...

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...

  • solve it in c++ 10 note: please do not give me same answer like this 1....

    solve it in c++ 10 note: please do not give me same answer like this 1. Define a Pet class that stores the pet's name, age, and weight. Add appropriate constructors, accessor functions, and mutator functions. Also define a function named getLifespan that returns a string with the value "unknown lifespan." Next, define a Dog class that is derived from Pet. The Dog class should have a private member variable named breed that stores the breed of the dog. Add...

  • Question 1 What is the value of x after the following int x = 5; x++;...

    Question 1 What is the value of x after the following int x = 5; x++; x++; x+=x++; A)14 B)10 C)13 D)15 Question 2 The last line in value returning function (before the }) should contain the word return. True False Question 3 This contains three parts: Void or Data Type the name optional parameter list A)Menu System B)Function Header C)Switch Question 4 What is a variable? A)a pointer B)a place in memory to hold data C)int D)a computer programming...

  • QUESTION 1 What will be displayed as a result of executing the following code? int   x...

    QUESTION 1 What will be displayed as a result of executing the following code? int   x = 5, y = 20; x += 32; y /= 4; cout <<"x = " << x <<"y = " << y; A. x = 32, y = 4 B. x = 9, y = 52 C. x = 37, y = 5 D. x = 160, y = 80 8 points    QUESTION 2 What will be the displayed when the following code...

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