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
Virty [35]
3 years ago
9

Given 4 integers, output their product and their average, using integer arithmetic.

Computers and Technology
1 answer:
solmaris [256]3 years ago
8 0

Answer:

see explaination

Explanation:

Part 1:

import java.util.Scanner;

public class LabProgram {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int num1;

int num2;

int num3;

int num4;

int avg=0, pro=1;

num1 = scnr.nextInt();

num2 = scnr.nextInt();

num3 = scnr.nextInt();

num4 = scnr.nextInt();

avg = (num1+num2+num3+num4)/4;

pro = num1*num2*num3*num4;

System.out.println(pro+" "+avg);

}

}

------------------------------------------------------------------

Part 2:

import java.util.Scanner;

public class LabProgram {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int num1;

int num2;

int num3;

int num4;

double avg=0, pro=1; //using double to store floating point numbers.

num1 = scnr.nextInt();

num2 = scnr.nextInt();

num3 = scnr.nextInt();

num4 = scnr.nextInt();

avg = (num1+num2+num3+num4)/4.0; //if avg is declared as a float, then use 4.0f

pro = num1*num2*num3*num4;

System.out.println((int)pro+" "+(int)avg); //using type conversion only integer part

System.out.printf("%.3f %.3f\n",pro,avg);// \n is for newline

}

}

You might be interested in
A call center company wants to implement a domain policy primarily for its shift workers. The call center has large groups with
spayn [35]

In my opinion, the best solution for the call center company to implement is to enforce time of day restrictions.

D) Time-of-day restrictions.

<u>Explanation:</u>

As the employees of the call-center company work in shifts, it would be the best solution to incorporate time of day restrictions. Each employee has already been allotted a shift, so every employee should only be allowed to log in when their shift is active.

Reduced failed logon attempts, mandatory password changes, and increased account-lockout time are also good practices to incorporate but the performance of the shift will be best monitored when the time of day restrictions are made.

In this way, the company will know who all from the employees are allowed to log in and it will subsequently decrease the traffic as well.

7 0
3 years ago
What do you understand by animation?How is it helpful in a presentations?​
aleksandrvk [35]

Answer:

Animation can help make a PowerPoint presentation more dynamic, and help make information more memorable. ... Animation can be useful in making a presentation more dynamic, and help to emphasize points, but too much animation can be distracting. Do not let animation and sound take the focus away from what you are saying.

Explanation:

TWACB

3 0
3 years ago
You wrote a program to allow the user to guess a number. Complete the code to give the user feedback.
geniusboy [140]

Answer:

The complete program is:

import random

keepGoing = True

num = random.randint(0,9)  

guess = int(input("Your guess: "))

while keepGoing == True:

   if num == guess:

       print("You were correct!")

       keepGoing = False

   else:

       print("You were wrong.")

       guess = int(input("Your guess: "))

       keepGoing = True

Explanation:

<em>To answer this program, I let the computer generate a random number, then let the user make a guess.</em>

<em></em>

This imports the random module

import random

This initializes a Boolean variable keepGoing to True

keepGoing = True

Generate a random number

num = random.randint(0,9)  

Let the user take a guess

guess = int(input("Your guess: "))

The loop is repeated until the user guesses right

while keepGoing == True:

Compare user input to the random number

   if num == guess:

If they are the same, then the user guessed right

       print("You were correct!")

Update keepGoing to False

       keepGoing = False

If otherwise,

   else:

then the user guessed wrong

       print("You were wrong.")

Prompt the user for another number

       guess = int(input("Your guess: "))

Update keepGoing to True

       keepGoing = True

8 0
3 years ago
Read 2 more answers
A program asks the user to enter the unit price of a chair and the quantity he is buying. It calculates and displays the total p
Shtirlitz [24]

Answer:

The c++ program for the given scenario is shown below.

#include <iostream>

using namespace std;

int main() {

   // variables declared for unit price, quantity, total price

// price is taken as double

// quantity is taken as integer

   double chair_price, total_price;

   int chair_qty;

   cout << " Enter the unit price of the chair : " << endl;

   cin >> chair_price;

   cout << " Enter the number of the chairs to be bought : " << endl;

   cin >> chair_qty;

   total_price = chair_price * chair_qty;

   cout << " The total price for " << chair_qty << " chairs is " << total_price << endl;

   return 0;

}

OUTPUT

Enter the unit price of the chair  

23.4

Enter the number of the chairs to be bought  

10

The total price for 10 chairs is 234

Explanation:

 

1. The variables for unit price, quantity of chairs and total price of chairs are declared. The reason for data type is explained below.

double chair_price, total_price;

   int chair_qty;

2. The variables are not initialized since their values is to be entered by the user.

3. First, the user is prompted to enter the unit price of the chair. This is stored in a double variable since price can be in decimals.

cin >> chair_price;

4. Next, the user enters the number of chairs to be bought. This value is stored in an integer variable since quantity can not be a decimal number.

cin >> chair_qty;

5. The total price is computed as the product of the unit price and the quantity of chairs. The total cost is also stored in a double variable since unit price can be in decimals.

total_price = chair_price * chair_qty;

6. Lastly, this total price is displayed to the standard output.

7. The keyword endl is used to insert new line.

4 0
3 years ago
Mille gets a text from her friend asking if she wants to come over. It seems like a bit of a hassle to go to her friend's house,
Licemer1 [7]

Answer:

OC. It will be a more positive experience if she spends time with her friend in person.

Explanation:

You should always spend time with people in person rather than online whenever you get the chance.

8 0
2 years ago
Other questions:
  • Pointers with classes a) A user-defined class named Timer has a constructor that takes two integer parameters to initialize hour
    14·1 answer
  • What is the value of vals[4][1]? double[][] vals = {{1.1, 1.3, 1.5}, {3.1, 3.3, 3.5}, {5.1, 5.3, 5.5}, {7.1, 7.3, 7.5}};
    6·1 answer
  • which of the following is an educated or informed guess that is proposed and supported with verifiable evidence
    12·1 answer
  • which field in the contact form is used to control the order in which contacts are displayed in the current view
    15·1 answer
  • An ideal line length would include how many characters? A. 6570 B. 100 C. 100125 D. 4055
    8·1 answer
  • What are the pros and cons of using the Internet for researching career information?
    14·2 answers
  • A database record can best be described as:
    11·1 answer
  • On an XBOX 360, what does it mean if you get 4 red rings on your console?
    5·1 answer
  • In excel online what is it called when you join connecting cells together to span across more than one column and/or row?
    7·2 answers
  • What is wrong here??
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!