1 answer

Warm up: Basic output with variables

Question:

1.14 LAB: Warm up: Basic output with variables

This zyLab activity prepares a student for a full programming assignment. Warm up exercises are typically simpler and worth fewer points than a full programming assignment, and are well-suited for an in-person scheduled lab meeting or as self-practice.

A variable like userNum can store a value like an integer. Extend the given program as indicated.

  1. Output the user's input. (2 pts)

  2. Output the input squared and cubed. Hint: Compute squared as userNum * userNum. (2 pts)

  3. Get a second user input into userNum2, and output the sum and product. (1 pt)

Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the next line, but such values don't actually appear as output when the program runs.

Enter integer: 4 You entered: 4 4 squared is 16  And 4 cubed is 64!! Enter another integer: 5 4 + 5 is 9 4 * 5 is 20

Answers

import java.util.Scanner;   public class OutputWithVars {     public static void main(String[] args) {           Scanner scnr = new Scanner(System.in);              int userNum;       int squared;       int cubed;       int userNumTwo;       int add;       int mult;        System.out.println("Enter integer:");       userNum = scnr.nextInt();                System.out.println("You entered: " + userNum);              squared = userNum * userNum;       System.out.println(userNum + " squared is " + squared);              cubed = userNum * userNum * userNum;       System.out.println("And " + userNum + " cubed is " + cubed + "!!");              System.out.println("Enter another integer:");       userNumTwo = scnr.nextInt();                add = userNum + userNumTwo;       System.out.println(userNum + " + " + userNumTwo + " is " + add);              mult = userNum * userNumTwo;       System.out.println(userNum + " * " + userNumTwo + " is " + mult);           }     }


.

Similar Solved Questions

1 answer
The boiling points of pure HF, HCl, HBr and HI are -20, -85, -66 and -34...
The boiling points of pure HF, HCl, HBr and HI are -20, -85, -66 and -34 C, respectively. Identify the trends in bond polarity and dispersion forces along this series. (i) Use this information to assess the relative strengths of these two effects in this case. (3 marks) Suggest a reason for the anom...
1 answer
Using the formula and you are supposed to get . Please show your steps for the...
Using the formula and you are supposed to get . Please show your steps for the double integration - I can do the rest 2. Find the vibrations of a rectangular membrane of sides a = 4 ft and b = 2 ft (Fig. 305) if the tension is 12.5 lb/ft, the density is 2.5 slugs/ft (as for light rubber), the init...
1 answer
Esign an npn-based Inverting Amplifier with "diode-connected" (gate-to drain) n-channel MOSFET load to meet these performance...
esign an npn-based Inverting Amplifier with "diode-connected" (gate-to drain) n-channel MOSFET load to meet these performance specifications 200 Hz &fai 220 kHz Complete signal path mid-band gain Ami 20 dB Linear Vout Swing 21 Vp BJT (npr) → designer's choice, but the 2N3904 is ...
1 answer
Charges A, B, and are arrayed along the y axis, with QA = -3,90 nC, 93.00...
Charges A, B, and are arrayed along the y axis, with QA = -3,90 nC, 93.00 nC, and c = 4.90 nC (see figure below). The distance between charges A and B is 71 - 1.00 m, and the distance between charges B and C is y2 = 2.60 m. 9A Vi 98 4c (a) What is the net electrostatic force on charge A? magnitude d...
1 answer
13. Apply the polygon nele to cyclobuta-1,3-dione. Make sur to include our applicable labels T a...
13. Apply the polygon nele to cyclobuta-1,3-dione. Make sur to include our applicable labels T a nt bonding interaction 127 Anon bonding line a) which molecular orbital is hignast in energy term degenerare mean with regard to mehaks b.) what does Ovitals C) what Rule states that electrons fill degen...
1 answer
Over years, a virus-infected cell slowly transformed into a cancerous cell exposing (due to mutations) changed...
Over years, a virus-infected cell slowly transformed into a cancerous cell exposing (due to mutations) changed antigens, i.e. proteins, on its cell surface. Which of the following cells of the immune system are most likely to recognize and attack this transformed cell?      ...
1 answer
QUESTION 4 The graphic symbol that can represent an operation or process is Rectangle (LO1) C...
QUESTION 4 The graphic symbol that can represent an operation or process is Rectangle (LO1) C Diamond Circle Parallelogram OOO...
1 answer
The figure shows a circuit containing three switches, labeled S1, S2, and S3. Find the current...
The figure shows a circuit containing three switches, labeled S1, S2, and S3. Find the current at "a" for all possible combinations of switch settings. Put e = 90 V, R1 = 20 Ohm, and R2 = 10 Ohm. Assume that the battery has no resistance. a. Current at "a" for S1 and S3 closed, S2 op...
1 answer
Double-Slit Experiment In a double-slit experiment, the second-order bright fringe is observed at an angle of...
Double-Slit Experiment In a double-slit experiment, the second-order bright fringe is observed at an angle of 0.60°. If the slit separation is 0.10 mm, then what is the wavelength of the light? Submit Answer Tries 0/12...
1 answer
2.   20% - Is Russia a suitable home market for TCL? How does it compare with...
2.   20% - Is Russia a suitable home market for TCL? How does it compare with other emerging market options?...
1 answer
Model A, shown on the following graph, refers to the regression of hours spent surfing the...
Model A, shown on the following graph, refers to the regression of hours spent surfing the web and productivity at work. MODEL A RESIDUALS CO -1 -2 -3 0 10 20 3040 50 60 We were unable to transcribe this image...
1 answer
These are my measurements. This is for physics its a RC LAB. The purpose is that...
These are my measurements. This is for physics its a RC LAB. The purpose is that for a discharging capacitor we measure voltage and from this we determine the capacitance. Also from thee measured capacitance we can find thee internal resistance of the voltmeter 1)measurements over resistor T(time...
1 answer
QS 11-2 Accounting for sales taxes LO C2 Dextra Computing sells merchandise for $8,000 cash on...
QS 11-2 Accounting for sales taxes LO C2 Dextra Computing sells merchandise for $8,000 cash on September 30 (cost of merchandise is $5,600). The sales tax law requires Dextra to collect 2% sales tax on every dollar of merchandise sold. Record the entry for the $8,000 sale and its applicable sales ta...
1 answer
Two disgruntled business people are trying to use a revolving door, as it is shown. The...
Two disgruntled business people are trying to use a revolving door, as it is shown. The woman on the left exerts a force of 625 N perpendicular to the door and 1.20 m from the hub's center, while the man on the right exerts a force of 850 N perpendicular to the door and 0.800 m from the hub'...
1 answer
Java Write a complete program that implements the functionality of a deck of cards. In writing...
Java Write a complete program that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two given classes. Use anonymous objects where appropriate. Deck c...
1 answer
A physician calls you to ask if you could compound a 5% oral solution of potassium...
A physician calls you to ask if you could compound a 5% oral solution of potassium chloride for a I. patient who needs to take 10 mEq of KCL orally daily. If 75 mg of KCl contains 1 mEq of potassium, how many teaspoonfuls of the 5% KCl solution would the patient need to take daily? II. You are asked...