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
Problem: you need to write a code that read 2 array of size 10x10 of zero and ones that represent black
castortr0y [4]

Answer:

import java.util.Scanner;

import java.lang.*;

public class Main

{

       //variables declared static; to be used inside main()

       static int err;

    static int size=10;

    //arrays declared static; to be used inside main()

       static int[][] white = new int[size][size];

       static int[][] black = new int[size][size];        

   //method to recognize any errors in the image    

   static int recognition(int[][] img)

   {

       //variable to indicate any error

       int notImage=0;

       if(img[1][1]==0)

       {

           for(int l=0;l<size; l++)

           {

               for(int k=0;k<size; k++)

               {

                   if(img[l][k]!=0)

                       notImage++;

               }

           }

       }

       else

       {

           for(int l=0;l<size; l++)

           {

               for(int k=0;k<size; k++)

               {

                   if(img[l][k]!=1)

                       notImage++;

               }

           }

       }

       if(notImage!=0)

           return -1;

       else    

           return 0;

   }

public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

 System.out.println("Enter the elements for 2d black array of size 10(enter 0): ");

 for(int l=0;l<size; l++)

       {

           for(int k=0; k<size; k++)

           {

               white[l][k]=sc.nextInt();    

           }

       }

 System.out.println("Enter the elements for 2d white array of size 10(enter 1): ");

 for(int l=0;l<size; l++)

       {

           for(int k=0; k<size; k++)

           {

               black[l][k]=sc.nextInt();    

           }

       }

 err = recognition(white);

 if(err==-1)

     System.out.println("White image has errors.");

 else    

     System.out.println("White image does not has errors.");

 

    err = recognition(black);

 if(err==-1)

     System.out.println("Black image has errors.");

 else    

     System.out.println("Black image does not has errors.");

}

}

OUTPUT

Program tested for smaller sizes.

Explanation:

1. Two two dimensional integer arrays are declared.

2. The variable size is declared and initialized to 10.

3. The main() prompts the user to enter the elements for both arrays; 1 for white and 0 for black.

4. Both the arrays are initialized inside two for loops independently.

5. These arrays are passed as parameter to the method, recognition(), one at a time.

6. Inside recognition(), an integer variable, notImage is declared and initialized to 0. If any other integer, other than 0 or 1 is encountered in the respective arrays, this variable is initialized to -1.

7. Inside main(), an integer variable, err, is declared. This variable stores the value returned by recognition().

8. Depending on the value of variable, err, message is displayed to the user appropriately.

3 0
3 years ago
What is an example of new technology having a negative impact on sustainability?.
Talja [164]

An example of new technology having a negative impact on sustainability is the use of computer automation to shut down unused electronic devices.

<h3>What is technology?</h3>

Technology can be defined as a field of science that involves the process of creating, applying, and managing scientific knowledge and ideas, so as to effectively and efficiently proffer solutions to various problems and cause an improvement in human life.

<h3>What is a computational sustainability?</h3>

Computational sustainability can be defined as a process through which societal, economic, ecological and societal resources are balanced for the future well-being of humanity, especially by developing computational models and using mathematical and information science techniques.

In this context, we can infer and logically deduce that an example of new technology having a negative impact on sustainability is the use of computer automation to shut down unused electronic devices.

Read more on computational sustainability here: brainly.com/question/25719495

#SPJ1

6 0
2 years ago
does someone know of a website where I can find free essays or assignments already answered (right or wrong, ain't matter), kind
nalin [4]

Answer:

Your

Explanation:

Taking answers from online is plagiarism. If you get caught, you could get in trouble. If you don't know the subject well enough that doesn't matter because apparently you don't care your grade.

5 0
3 years ago
which two statements about incoming and outgoing interfaces in firewall policies are true? (choose two.)
Ratling [72]

The statements that are true regarding incoming and outgoing interfaces in firewall policies are:

  • A zone can be chosen as the outgoing interface.
  • -Multiple interfaces can be selected as incoming and outgoing interfaces.

<h3>What is a firewall?</h3>

A firewall is a network security device used in computing that monitors and regulates incoming and outgoing network traffic in accordance with pre-established security rules. Typically, a firewall creates a wall between a trustworthy network and an unreliable network, like the Internet.

A firewall aids in defending your network from intruders. A firewall protects your network by operating as a continuous filter that constantly scans incoming data and blocks anything that appears to be suspicious.

Therefore, the statements that are true regarding incoming and outgoing interfaces in firewall policies are:

A zone can be chosen as the outgoing interface.

-Multiple interfaces can be selected as incoming and outgoing interfaces.

Learn more about firewall on:

brainly.com/question/13693641

#SPJ1

Which statements are true regarding incoming and outgoing interfaces in firewall policies? (Choose two.)

Select one or more:

-An incoming interface is mandatory in a firewall policy, but an outgoing interface is optional.

-A zone can be chosen as the outgoing interface.

-Only the any interface can be chosen as an incoming interface.

-Multiple interfaces can be selected as incoming and outgoing interfaces.

4 0
2 years ago
5. Bits are sent over a communications channel in packets of 12. (a) If the probability of a bit being corrupted over this chann
user100 [1]

Answer:

0.889

Explanation:

7 0
4 years ago
Other questions:
  • Achieving a degree in computer forensics, information technology, or even information systems can provide a strong foundation in
    11·1 answer
  • Does any body like animal jam
    11·2 answers
  • The document theme does not determine the appearance of the style
    6·1 answer
  • 1. Write a CFG to generate identifiers (IDs) in the Java Programming Language. An ID in Java is a string of characters consistin
    5·1 answer
  • What is a System Software ?
    11·2 answers
  • Match each code snippet to its appropriate markup language name. XML CSS HTML XHTML<br><br><br>​
    10·1 answer
  • Comments should Your answer: rephrase the code it explains in English be insightful and explain what the instruction's intention
    15·1 answer
  • Which of the following statements is TRUE of a peer-to-peer network?
    10·1 answer
  • What is the two’s compliment of -95,-122,-111,-57
    9·1 answer
  • A major way the National Information Infrastructure Protection Act of 1996 amended the Computer Fraud and Abuse Act was the subs
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!