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
BartSMP [9]
3 years ago
12

A variable like userNum can store a value like an integer. Extend the given program to print userNum values as indicated.(1) Out

put the user's input.Enter integer: 4You entered: 4(2) Extend to output the input squared and cubed. Hint: Compute squared as userNum * userNum. (Submit for 2 points, so 4 points total).Enter integer: 4You entered: 44 squared is 16 And 4 cubed is 64!! (3) Extend to get a second user input into userNum2. Output sum and product. (Submit for 1 point, so 5 points total).Enter integer: 4You entered: 44 squared is 16 And 4 cubed is 64!!Enter another integer: 54 + 5 is 94 * 5 is 20LABACTIVITY1.16.1: Basic output with variables (Java)0 / 5OutputWithVars.javaLoad default template...import java.util.Scanner;public class OutputWithVars {public static void main(String[] args) {Scanner scnr = new Scanner(System.in);int userNum = 0;System.out.println("Enter integer: ");userNum = scnr.nextInt(); return;}}import java.util.Scanner;public class OutputWithVars {public static void main(String[] args) {Scanner scnr = new Scanner(System.in);int userNum = 0;System.out.println("Enter integer: ");userNum = scnr.nextInt();return;}}Develop modeSubmit modeRun your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box.
Computers and Technology
1 answer:
dimulka [17.4K]3 years ago
8 0

Answer:

The program in Java is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

 int userNum;

 Scanner input = new Scanner(System.in);

 System.out.print("Enter integer: ");

 userNum = input.nextInt();

 System.out.println("You entered "+userNum);

 System.out.println(userNum+" squared is "+(userNum*userNum));

 System.out.println(userNum+" cubed is "+(userNum*userNum*userNum));

 int userNum2;

 System.out.print("Enter another integer: ");

 userNum2 = input.nextInt();

 int sum= userNum + userNum2; int product = userNum2 * userNum;

 System.out.println(userNum+" + "+userNum2+" = "+sum);

 System.out.println(userNum+" * "+userNum2+" = "+product); } }

Explanation:

This declares userNum

 int userNum;

 Scanner input = new Scanner(System.in);

This prompts the user for input

 System.out.print("Enter integer: ");

This gets user input from the user

 userNum = input.nextInt();

Number (1) is implemented here

 System.out.println("You entered "+userNum);

Number (2) is implemented here

 System.out.println(userNum+" squared is "+(userNum*userNum));

 System.out.println(userNum+" cubed is "+(userNum*userNum*userNum));

This declares another variable userNum2

 int userNum2;

This prompts the user for another input

 System.out.print("Enter another integer: ");

This gets user input from the user

 userNum2 = input.nextInt();

This calculates the sum and the product

 int sum= userNum + userNum2; int product = userNum2 * userNum;

Number (3) is implemented here

 System.out.println(userNum+" + "+userNum2+" = "+sum);

 System.out.println(userNum+" * "+userNum2+" = "+product);

You might be interested in
THE AVERAGE OF 6 NUMBERS IS 19 THE AVERAGE OF FIVE OF THESE IS 20 WHAT IS THE SIXTH NUMBER
Paraphin [41]
Let us consider a, b, c, d, e, f the six numbers.
If the average of 6 numbers is 19 then
(a + b + c + d + e + f)/6 = 19
=> a + b + c + d + e + f = 114 (1)
And if the average of 5 numbers is 20 then
(a + b + c + d + e)/5 = 20
=> a + b + c + d + e = 100 (2)
We will replace (2) in (1) And it will result that
100 + f = 114 => f=114, the sixth number.
8 0
3 years ago
Create an array of doubles to contain 5 values Prompt the user to enter 5 values that will be stored in the array. These values
Gre4nikov [31]

Solution :

$\#$include $$  

$\#$include $$    

void parse$\_$name($char \ full[]$, char first$[],$ char last$[])$

{

// to_get_this_function_working_immediately, _irst

// stub_it_out_as_below._When_you_have_everything_else

// working,_come_back_and_really_parse_full_name

// this always sets first name to "Noah"

int i, j = 0;

for(i = 0; full[i] != ' '; i++)

  first[j++] = full[i];

first[j] = '\0';  

// this always sets last name to "Zark"

j = 0;

strcpy(last, full+i+1);

// replace the above calls with the actual logic to separate

// full into two distinct pieces

}

int main()

{

char full[40], first[20], last[20];

double hours[5];

// ask the user to enter full name

printf("What is your name? ");

gets(full);

// parse the full name into first and last

parse_name(full, first, last);

// load the hours

for(int i = 0; i < 5; i++)

{

   printf("Enter hours for day %d: ", i+1);

   scanf("%lf", &hours[i]);

}

// create the time card

FILE* fp = fopen("timecard.txt", "w");

fprintf(fp, "First Name: %s\n", first);

fprintf(fp, "Last Name: %s\n", last);

double sum = 0.0;

for(int i = 0; i < 5; i++)

{

   fprintf(fp, "Day %i: %.1lf\n", i+1, hours[i]);

   sum += hours[i];

}

fprintf(fp, "Total: %.1f\n", sum);    

printf("Timecard is ready. See timecard.txt\n");

return 0;

}

3 0
3 years ago
Which of the following are disadvantages of networks? Check all of the boxes that apply.
RideAnS [48]

Answer:

• Network intruders can access all computers on a network.

• Networks are costly to set up.

Explanation:

A network can be defined as a connection between the internet and the computer. A network is a means by which information or data are transmitted from one computer to another.

We have various types of networks and some of them are:

a) Local Area Network (LAN)

b) Wireless Local Area Network (WLAN)

c) Wide Area Network (WAN)

d) Campus Area Network (CAN)

e) Metropolitan Area Network (MAN)

f) Personal Area Network (PAN) e.t.c

The disadvantages of network are:

a) Network intruders such as computer hackers can easily access all computers on a network.

b) Networks are costly to set up.

It is of outermost importance that a network used by a computer is secured using security such as encryption in other to prevent data loss , hackers and exposure of information that are sensitive to computer users.

4 0
3 years ago
Wired technology differs from wireless because
ratelena [41]

Answer:

Explanation: Wired technology differs from wireless because

it is connected by a physical wire

8 0
3 years ago
How should you handle cyberbullies?
damaskus [11]

Answer:

insult those son of a bishes backk

8 0
3 years ago
Read 2 more answers
Other questions:
  • How do I convert a number into a percentage in excel
    7·1 answer
  • The processor in Q1 above is converted into an 8-stage pipeline, similar to the one discussed on slide 8 of lecture 16. It takes
    6·1 answer
  • Assume that play_list refers to a non-empty list, and that all its elements are integers. Write a statement that associates a ne
    7·1 answer
  • Universal Container sales reps can modify fields on an opportunity until it is closed. Only the sales operations team can modify
    13·1 answer
  • You are auditing a client's network and have gained physical access to a workstation. To prevent any security software from dete
    10·1 answer
  • 6.10.1: Modify a C string parameter. Complete the function to replace any period by an exclamation point. Ex: "Hello. I'm Miley.
    8·1 answer
  • Internet Security: How can you work securely on the internet? What actions should be avoided and what are the pitfalls?
    9·1 answer
  • Brian is a computer engineer who writes security software for a banking system. The
    13·1 answer
  • Under the Gramm-Leach-Bliley-Act (GLBA), banks must protect customer privacy. A given bank has just implemented its online banki
    9·1 answer
  • What is an insertion point?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!