1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
expeople1 [14]
3 years ago
11

Find and fix the error in the if-else statement. import java.util.Scanner;

Computers and Technology
2 answers:
salantis [7]3 years ago
3 0

Answer:

Hi there Rumanruxi! The error is in the if statement "if(userNum = 2)".

Explanation:

The if statement in this Java code is assigning userNum the value of 2 instead of comparing it with the value of 2. For equals comparison we need to write two equals "==" in the statement as: "if (userNum == 2)". This will return true if userNum is 2 otherwise it will return false.  

andriy [413]3 years ago
3 0

Answer:

The error generated when the code is compiled:

incompatible types: int cannot be converted to boolean

Explanation:

This error is generated because the variable userNum is being assigned the value of 2.

userNum= 2

here = is the assignment operator used to assign the value 2 to the variable userNum

But here we need to compare the values with the value 2. So in order to compare the values in IF statement, == is used which is called the equality operator, instead of =

So the corrected if statement is:

if(userNum==2)

So the program prompts the user to enter a value (0,1,2,3) which is read in the userNum. Next the if statement checks if that input value is equal to 2. Num is equal to two message is displayed in the output when the if condition evaluates to true and Else part is executed if the condition evaluates to false and Num is not two message is displayed in the output.

For example the user enters a value 1 then the following message will be displayed in the output:

Num is not two

If the user enters 2 then the following message will be displayed in the output:

Num is equal to two

You might be interested in
Cell address A4 in a formula means it is a _________Mixed cell reference
WITCHER [35]

Answer:

A. Relative cell reference.

Explanation:

A relative cell reference is like a pointer to a cell or range of cell in Excel. In Excel all cell references, by default, are relative cell references.

In the given instance, the cell address A4 in a formula means it is a relative cell reference. If there would have been a $ sign before A4, then it will be an absolute cell reference. But since, it is without dollar sign, it is a relative cell reference.

Therefore, option A is correct.

4 0
3 years ago
If a student passes off an author’s work as his or her own, the student has
Taya2010 [7]
Plagiarism is the answer
7 0
3 years ago
What is an lms and how is it used
Georgia [21]
A learning management system (LMS) is a software application for the administration, documentation, tracking, reporting and delivery of educational courses or training programs.
3 0
4 years ago
Read 2 more answers
Cryptography has requirements include:
ki77a [65]

Answer:

A

Explanation:

Cryptography is the study of secure communications techniques that allow only the sender and intended recipient of a message to view its contents. ... When transmitting electronic data, the most common use of cryptography is to encrypt and decrypt email and other plain-text messages.

4 0
3 years ago
Alright, so im currently trying to pass a computer science class. i need it done in a little under 2 weeks. Ill just ask the one
Alla [95]

Answer:

B. Mesh

Explanation:

5 0
3 years ago
Other questions:
  • Slack space most commonly contains visible data. True or false?
    15·1 answer
  • Is a small file that a web server writes to the disk drive of the client computer, containing information about the user?
    8·1 answer
  • The class dateType was designed to implement the date in a program, but the member function setDate and the constructor do not c
    6·2 answers
  • Rose opens her software application and gets a message stating that she has only 16 more uses of the product available. Given th
    15·1 answer
  • A clock is reading 10:27:54.0 (hr:min:sec) when it is discovered to be 4 seconds fast. Explain why it is undesirable to set it b
    9·1 answer
  • What keyboard functions lets you delete words
    9·2 answers
  • Why are there problems with patching electronics such as heart rate monitors and MRI machines that run embedded Windows OSs?
    14·1 answer
  • What's wrong with this python code i don't know what's wrong with both of them
    11·1 answer
  • Need help with Python coding from Zybooks...
    9·1 answer
  • A software development team needs to upgrade a program, but the team members are having trouble understanding the program code a
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!