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
Aleks [24]
3 years ago
12

g Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative inte

gers as input, and outputs the average and max. A negative integer ends the input and is not included in the statistics. Ex: When the input is:
Computers and Technology
1 answer:
AnnZ [28]3 years ago
6 0

Answer:

import java.util.Scanner;

public class LabProgram

{

  public static void main(String[] args) {

  Scanner sc = new Scanner(System.in);//to read input

  int count=0;//to keep track of the count of numbers entered

  int max=0;//to store the maximum value

  int sum=0;//to store the sum of numbers entered

  double av=0;//to calculate and store the average

  //reading inputs until a negative number is entered

  while(true)

  {

  int n = sc.nextInt();//reading input

  if(n<0)//if negative number

  break;//then stopping loop

  count++;//increasing count

  if(count==1)//means it is first number

  max=n;

  else if(max<n)//if current number is greater than previous max

  max=n;//updating max

  sum+=n;//adding new number to sum

  }

  //finding average

  av = (double)sum/count;

  //displaying output

      System.out.println((int)av+" "+max);//remove type casting (int) here, if you want decimal places also

  }

}

You might be interested in
Whoever helps me with these questions i will help them with the same number of questions in any subject: 1. As the operations ma
mezya [45]
I'm going have to go with with 1.b and 2.d hope this helps and I don't need help right now.
6 0
3 years ago
Technician A says that the excessive length of a heater hose is intended to protect the heater core from undue stress. Technicia
hammer [34]
It is both true that <span>Technician A says that the excessive length of a heater hose is intended to protect the heater core from undue stress. Technician B says that excessive wear adds to the length of a heater hose, and a replacement heater hose should be roughly three to four inches shorter than its predecessor.  So the asnwer is letter B.</span>
6 0
3 years ago
Web navigation gives the user a sense of control.
Leviafan [203]
1. a.
2. d
3. b
I hope this helps
6 0
3 years ago
Read 2 more answers
What method does a GSM network use to separate data on a channel?
Sergeu [11.5K]

Answer: TDMA(Time division multiple access)

Explanation: Time-division multiple access is the method that is used by GSM(Global system for mobile communication) usually for the separation process of the data.It is a way in which a same frequency is shared by different time slots of signal.It has high flexibility and so thus is helpful for the GSM network and provides easy services of division.It divides the data according to the time period slots in a GSM network.

4 0
3 years ago
Building a String Library
maw [93]
Code:

def myAppend( str, ch ):
# Return a new string that is like str but with
# character ch added at the end
return str + ch

def myCount( str, ch ):
# Return the number of times character ch appears
# in str.

# initiaalizing count with 0
count = 0

# iterating over every characters present in str
for character in str:
# incrementing count by 1 if character == ch
if character == ch:
count += 1

# returning count
return count


def myExtend( str1, str2 ):
# Return a new string that contains the elements of
# str1 followed by the elements of str2, in the same
# order they appear in str2.

# concatenating both strings and returning its result
return str1 + str2

def myMin( str ):
# Return the character in str with the lowest ASCII code.

# If str is empty, print "Empty string: no min value"
# and return None.
if str == "":
print("Empty string: no min value")
return None

# storing first character from str in char
char = str[0]

# iterating over every characters present in str
for character in str:
# if current character is lower than char then
# assigning char with current character
if character < char:
char = character
# returning char
return char


def myInsert( str, i, ch ):
# Return a new string like str except that ch has been
# inserted at the ith position. I.e., the string is now
# one character longer than before.

# Print "Invalid index" if
# i is greater than the length of str and return None.

if i > len(str):
print("Invalid index")
return None

# str[:i] gives substring starting from 0 and upto ith position
# str[i:] gives substring starting from i and till last position
# returning the concatenated result of all three
return str[:i]+ch+str[i:]

def myPop( str, i ):
# Return two results:
# 1. a new string that is like str but with the ith
# element removed;
# 2. the value that was removed.
# Print "Invalid index" if i is greater than or
# equal to len(str), and return str unchanged and None
if i >= len(str):
print("Invalid index")
return str, None

# finding new string without ith character
new_str = str[:i] + str[i+1:]

# returning new_str and popped character
return new_str, str[i]

def myFind( str, ch ):
# Return the index of the first (leftmost) occurrence of
# ch in str, if any. Return -1 if ch does not occur in str.

# finding length of the string
length = len(str)

# iterating over every characters present in str
for i in range(length):
# returning position i at which character was found
if str[i]==ch:
return i
# returning -1 otherwise
return -1


def myRFind( str, ch ):
# Return the index of the last (rightmost) occurrence of
# ch in str, if any. Return -1 if ch does not occur in str.

# finding length of the string
length = len(str)

# iterating over every characters present in str from right side
for i in range(length-1, 0, -1):
# returning position i at which character was found
if str[i]==ch:
return i
# returning -1 otherwise
return -1

def myRemove( str, ch ):
# Return a new string with the first occurrence of ch
# removed. If there is none, return str.

# returning str if ch is not present in str
if ch not in str:
return str

# finding position of first occurence of ch in str
pos = 0

for char in str:
# stopping loop if both character matches
if char == ch:
break
# incrementing pos by 1
pos += 1

# returning strig excluding first occurence of ch
return str[:pos] + str[pos+1:]

def myRemoveAll( str, ch ):
# Return a new string with all occurrences of ch.
# removed. If there are none, return str.

# creating an empty string
string = ""

# iterating over each and every character of str
for char in str:
# if char is not matching with ch then adding it to string
if char!=ch:
string += char
# returning string
return string

def myReverse( str ):
# Return a new string like str but with the characters
# in the reverse order.

return str[::-1]
6 0
2 years ago
Other questions:
  • If you want to boot from a hard drive what must it have
    6·1 answer
  • Cloud resources are​ ________ because many different organizations use the same physical hardware.
    12·1 answer
  • 1. Why was the Internet created?
    8·1 answer
  • A table is a useful way to present information that is organized into categories, or fields.
    15·1 answer
  • Write two cin statements to get input values into birthMonth and birthYear. Then write a statement to output the month, a dash,
    7·1 answer
  • If your TV was showing a flat black or blue screen, or had "snow", what steps would you take to fix it?
    13·1 answer
  • Select all the sets that are countably infinite. Question 3 options: the set of real numbers between 0.1 and 0.2 the set of all
    12·1 answer
  • A buffer storage that improve computer performance by reducing access time is​
    13·1 answer
  • What is the output of this program? Assume the user enters 2, 5, and 10.
    6·1 answer
  • What is the correct sequence in which a computer operates​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!