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]
4 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]4 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
Find the domain and range of Y=x^3-9/x-3​
dmitriy555 [2]
847nduak388jejdidmenrf838484858686
6 0
3 years ago
G Suite for Education offers which benefits to educators? (Select all that apply.) Select All Correct Responses Android apps ava
alukav5142 [94]

Answer:

The correct options are;

1) Android apps available on select chrome books

2) Domain admin can install apps

3) App permissions reviewed by domain admin for student safety

Explanation:

Select Chrome books work with android apps including does part of G -Suite for Educators such ,  Class room, Contacts, Drive, Vault,  Docs, For ms, Sheets

Domain administrators can manage school owned devices and applications including installing an app

Part of managing the domain includes the review of per missions for apps for student safety.

4 0
3 years ago
In a List of Positive Integers, Set MINIMUM to 1. For each number X in the list L, compare it to MINIMUM. If X is smaller, set M
Dvinal [7]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The given problem scenario is:

In a List of Positive Integers, Set MINIMUM to 1. For each number X in the list L, compare it to MINIMUM. If X is smaller, set MINIMUM to X.

The answer to question A is: this algorithm will not run because:

If you a list of a positive number and you have already set it MINIMUM to 1, the comparison result with MINIMUM will not obtain. For example, lets suppose a list of numbers L. L={1,2,3,1,1,5,4,3,2}. You have already set the Minimum to 1. When you compare each number X in the list, if X >MINIMUM, then set MINIMUM to X.  

This will not work, because there are positive numbers in the list and the minimum positive number is 1. So the algorithm, will not execute the if-part.

In short, the pseudo-code of this problem is given below:

<em>L={list of positive number e.g. 1,2,3,.......Xn}</em>

<em>MINIMUM=1</em>

<em>foreach ( X in L)</em>

<em>{</em>

<em>(if X<MINIMUM)</em>

<em>    { </em>

<em>        MINIMUM=X</em>

<em>    }</em>

<em>}</em>

The answer to question B is X will not be replaced because X  replaced with MINIMUM only when if-part of this algorithm get executed. However, it is noted that X will not replace any value, if if-part will get executed, the Variable MINIMUM will get replaced with any value.

4 0
3 years ago
âwhat service uses a private cloud in conjunction with a web browser or downloaded client software to access desktop software?
Vera_Pavlovna [14]
<span>The answer should be: Virtual Desktop Infrastructure</span>
5 0
4 years ago
Using the program below, explain what the output will be at LINE A. 1 #include 2#include 3#include 4 5 int value - 128; 6 7 int
slega [8]

Answer:

This is the complete correct program:

#include <stdio.h>

#include<sys/types.h>

#include<unistd.h>

int value = 128;

int main()

{

  pid_t pid;

  pid=fork();

  if (pid==0) /* child process */

  {

  value +=8;

  return 0; }

  else if (pid > 0) {/* parent process */

 wait (NULL);

 printf ("PARENT: value =%d\n" ,value); /* LINEA */

 return 0;

}

}

The output of the LINE A is:

PARENT: value = 128

Explanation:

The fork() function used in the program creates a new process and this process is the child process. The child process is same as the original process having its own address space or memory.

In the child process the value of pid is 0. So the if condition checks if pid==0. Then the child process adds 8 to the value of its variable according to the following statement  

value +=8;

Now the original process has value = 128. In else if part the parents process has the value of pid greater than zero and this portion of the program is of the parent process :

else if (pid > 0)

{ wait (NULL);

printf ("PARENT: value =%d\n" ,value);

return 0; }

So the value 128 is printed at the end in the output.

wait(NULL) is used to wait for the child process to terminate so the parent process waits untill child process completes.

So the conclusion is that even if the value of the variable pid is changed in the child process but it will not affect the value in the variable of the parent process.

5 0
3 years ago
Other questions:
  • Elsa has collated information for a meeting using Excel. Due to certain developments, some of the data in her worksheet is now r
    6·1 answer
  • "re-type the celsius_to_kelvin function. Change the name to kelvin_to_celsius, and modify the function accordingly."
    7·2 answers
  • Which type of microphone uses two metal plates?
    7·1 answer
  • Some projectors use a connection technology called _______________ that enables long-range connectivity for uncompressed HD vide
    12·1 answer
  • Sarah is a busy real estate agent with a growing clientele. She is looking to purchase a new computer and software so that she c
    15·1 answer
  • Which of these programmers creates the core game engine?
    5·2 answers
  • The addresses a program may use to reference memory are distinguished from the addresses the memory system uses to identify phys
    15·1 answer
  • A void function can return any value. TRUE FALSE
    8·1 answer
  • Which retouching action is unethical?
    8·1 answer
  • Answer for 3 and 4 please
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!