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
leva [86]
3 years ago
10

In Java please:Re-type the code and fix any errors. The code should convert non-positive numbers to 1. if (userNum > 0) Syste

m.out.println("Positive."); else System.out.println("Non-positive, converting to 1."); userNum = 1; System.out.println("Final: " + userNum);
Computers and Technology
1 answer:
iren2701 [21]3 years ago
8 0

Answer:

import java.util.Scanner;

public class Solution {

   public static void main(String args[]) {

       Scanner scan = new Scanner(System.in);

       int userNum = scan.nextInt();

       if (userNum > 0) {

           System.out.println("Positive.");

           

       } else {

           System.out.println("Non-positive, converting to 1.");

           userNum = 1;

           System.out.println("Final: " + userNum);

           

       }

   }

}

Explanation:

There was no error found when the code was run. The code segment was just added to a main method and it runs successfully.

Based on the full code above;

The first line import the Scanner class which allow the program to receive user input. Then the class was defined as Solution. Then the main method was defined. Inside the main method, we created a scanner object scan which receive the input via keyboard. The user input is assigned to the variable userNum. Then the if-conditional statement is executed; if userNum is greater than 0, "Positive" is output. Else userNum is converted to 1 and outputted to the screen.

You might be interested in
Write a shell (text-based) program, called sum_second.py, that opens a text file called stuff.txt with 2 numbers per line separa
Ivanshal [37]

Answer:

See explaination for the program code

Explanation:

The Programming code:

inFile = open("stuff.txt", "r")

num = []

Sum = 0

for val in inFile.readlines():

value = val.split(",")

Sum = Sum + int(value[1])

print("Sum of second number on every line in the file is: ", Sum)

inFile.close()

Please kindly check attachment for output

6 0
3 years ago
Write a program to calculate the area of a triangle whose base is 10cm and height is 6cm
Tcecarenko [31]

Answer:

30cm

Explanation:

Height X Base

6cm X 10cm

60cm

Then take half because a triangle is half a square and we are using a square formula.

60cm divided by 2

=30cm

7 0
3 years ago
Whether you work in m-commerce, e-commerce, or brick-and-mortar commerce, to be successful you will need to be able to think cri
svlad2 [7]

Answer:

The answer is "Option c"

Explanation:

Decisions made in secret have always been critical. Hence the want to express it before your choice is made. It is all about how you express choice. In general, they need your presentation to explain the choice that you decided, how they created it, and how it implies for just the group, that you are approaching, and wrong choices can be described as follows:

  • In option a, It is used in the industry to interest.
  • In option b, It is use in communication mechanism.
  • In option d, It enables people to handle our activities or carry them out.
3 0
3 years ago
application that will perform a lot of overwrites and deletes of data and requires the latest information to be available anytim
o-na [289]

Answer:

RDS.

Explanation:

A corporation has implemented a software that conducts the number of information overwriting and deleting, which allows the newest details to be accessible whenever the information is examined. As a Software Engineer, they suggest RDS database technologies.

It is an AWS supported controlled SQL DB service that also reinforces the array type DB for the purpose to contain and maintain the information.

3 0
4 years ago
When conducting research on the internet, what is a starting point for determining how to start the research?
Alex787 [66]
It depends on what you're researching for.
4 0
4 years ago
Other questions:
  • Which of the following is a goal of paraphrasing and summarizing?
    14·2 answers
  • Which command is used to combine two or more cells together into one cell?
    14·2 answers
  • This device is used to connect sections of large networks?
    12·2 answers
  • How can I collect tweets from different accounts concurrently and categorize the tweets in a corpus?
    15·1 answer
  • What are the features of Cobol language that make it suitable for programming business applications.
    6·1 answer
  • 5. Question<br> The control flag that isn't really in use by modern networks is the<br> flag.
    15·1 answer
  • An automatic transmission is a mechanism that _
    7·1 answer
  • what will allow you to immediately exit the program without rebooting the computer, when you realize your browser is not respond
    7·1 answer
  • Leon wants an output from his tablet. What should he look at?
    9·1 answer
  • Missing appropriate security hardening across any part of the application stack or improperly configured permissions is an examp
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!