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
MrRissso [65]
3 years ago
3

Re-type the code and fix any errors. The code should convert non-positive numbers to 1.if (userNum > 0) System.out.println("P

ositive.");else System.out.println("Non-positive, converting to 1."); userNum = 1;System.out.println("Final: " + userNum);Common student error: Changing the order of the lines. You only need to fix the existing code. import java.util.Scanner;public class ConvertNegative { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int userNum; userNum = scnr.nextInt(); /* Your solution goes here */ }}
Computers and Technology
1 answer:
Step2247 [10]3 years ago
6 0

Answer:

The above question code has only one wrong statement with the curly braces. If the user added the curly braces to the else part including two statements, then the code will display the correct result. The code after added the curly braces is as follows:-

if (userNum > 0) //Taken from the question.

System.out.println("Positive."); //Taken from the question.

else //Taken from the question.

{ // it will be added to the question code.

System.out.println("Non-positive, converting to 1."); //Taken from the question.

userNum = 1; //Taken from the question.

} // it will be added to the question code.

System.out.println("Final: " + userNum); //Taken from the question.

Output:

  • If the user inputs 4 then it will print the "positive number".
  • If the user inputs -9 then it will print the 1 as the final value

Explanation:

  • The question code is not given the right result for the value of a positive number.
  • The question said that if the value is negative then only the 1 will be printed.
  • But the question code will print 1 for the case of positive value also.
  • It is because there are no curly braces in the else-statement. So the else statement took only one statement within its block which is a print statement.
  • And the other statement is outside the else block which is assigned the 1 value to the final variable which will be printed.
  • So if the curly braces are fixed to decide the two statement, the print statement, and the assignment statement, then it will not print 1 for a positive value.

You might be interested in
What type of electronic monitoring involves an offender being contacted periodically by telephone or beeper to verify his or her
Masja [62]
The type of electronic monitoring that involves an offender being contacted periodically by telephone or beeper to verify his or her whereabouts is called the programmed contact. It is a method used in investigations to monitor the offender in a certain situation where he is forced to remain.
7 0
3 years ago
PLEASE HELP WITH MY CODING!!!!!!!!!!!!!!
igor_vitrenko [27]
A: Similar..............
6 0
3 years ago
Read 2 more answers
How do programmers recognise patterns, generalise and abstract information
Dima020 [189]

Answer:

Pattern recognition is the process of recognizing patterns by using machine learning algorithm. ... In a typical pattern recognition application, the raw data is processed and converted into a form that is amenable for a machine to use. Pattern recognition involves classification and cluster of patterns

Explanation:

4 0
3 years ago
Which type of service offers a preconfigured testing environment for application developers to create new software applications?
Vaselesa [24]

A type of service which offers a preconfigured testing environment for application developers to create new software applications is: B - Platforms as a Service (PaaS).

<h3>What is cloud computing?</h3>

Cloud computing can be defined as a type of computing service that requires the use of shared computing resources over the Internet, rather than the use of local servers and hard drives.

<h3>The categories of cloud service.</h3>

Generally, cloud computing comprises three (3) service models which includes the following;

  • Infrastructure as a Service (IaaS).
  • Software as a Service (SaaS).
  • Platform as a Service (PaaS).

In conclusion, a type of service which offers application developers a preconfigured hosting and testing environment to create new software applications is Platforms as a Service (PaaS).

Read more on Platform as a Service here: brainly.com/question/24233315

#SPJ1

6 0
2 years ago
In a relational database model, a(n) _____ operation pares down a table by eliminating columns according to certain criteria. in
nikklg [1K]

I guess the correct answer is Project

If thе usеr is intеrеstеd in sеlеcting thе valuеs οf a fеw attributеs, rathеr than sеlеctiοn all attributеs οf thе Tablе (Rеlatiοn), thеn οnе shοuld gο fοr Prοjеct Οpеratiοn.

8 0
3 years ago
Other questions:
  • The name of the opening that lets light into any camera is called ________.
    11·2 answers
  • . The toasting cycle of an automatic toaster is started by A. pushing the bread rack down. B. pushing the start button. C. turni
    14·2 answers
  • Two different ways to bring up My Computer folder
    11·1 answer
  • Why does Zoologist have no work experience in a related occupation?
    5·1 answer
  • The exponential distribution is often used to model what in a queuing system?
    12·1 answer
  • I WILL GIVE BRAINLIEST TO WHO ANSWERS FIRST AND CORRECTLY.
    12·1 answer
  • What is the definition of trouble shooting.
    12·1 answer
  • Select three advantages of cloud computing.
    12·1 answer
  • What is a typical use for a MAN?
    13·1 answer
  • What does an arrow after a command indicate
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!