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
LUCKY_DIMON [66]
4 years ago
13

Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The pro

gram should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be:
Computers and Technology
1 answer:
galben [10]4 years ago
8 0

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        int num[] = new int[51];
  5.        Scanner input = new Scanner(System.in);
  6.        System.out.print("Number of input: ");
  7.        int limit = input.nextInt();
  8.        for(int i=0; i < limit; i++){
  9.            System.out.print("Input a number (1-50): ");
  10.            int k = input.nextInt();
  11.            num[k]++;
  12.        }
  13.        for(int j=1; j < 51; j++){
  14.            if(num[j] > 0){
  15.                System.out.println("Number of occurrence of " + j + ": " + num[j]);
  16.            }
  17.        }
  18.    }
  19. }

Explanation:

The solution is written in Java.

Firstly, create an integer array with size 51. The array will have 51 items with initial value 0 each (Line 5).

Create a Scanner object and get user entry the number of input (Line 6-7).

Use the input number as the limit to control the number of the for loop iteration to repeatedly get integer input from user (Line 9-13). Whenever user input an integer, use that integer, k, as the index to address the corresponding items in the array and increment it by one (LINE 11-12).

At last, create another for loop to iterate through each item in the array and check if there is any item with value above zero (this means with occurrence at least one). If so, print the item value as number of occurrence (Line 14-17).

You might be interested in
Site three uses of powerpoint when it is used for educational purposes.​
CaHeK987 [17]
1. It can be used to create a slideshow for that class.
2. It can used as a place to keep and check grades.
3. It can be used for a place to keep all the students names and where they sit etc.
5 0
3 years ago
Energy consumption is measured in units of kilowatt hours (kWh). The more kWh a household use in a month, the higher the energy
3241004551 [841]

Answer:

The c# program for the scenario is given below.

using System;

public class Program {

 double total = 0;

 static void Main() {

     Program ob = new Program();

   Console.WriteLine("Enter total energy used in kilo watts ");

   int p;

   p = Convert.ToInt32(Console.ReadLine());

   ob.bill_calculator(p);

   Console.WriteLine("Total charge for " + p + " kilo watts of energy is " + ob.total);

 }

 public void bill_calculator(int e)

 {

     int first=500;

     double chg_one = 0.12, chg_two=0.15;

     if(e <= 500)

     {      

         total = (e * chg_one);

     }

     else if(e > 500)

     {

         total = ( first * chg_one);

         total = total + ((e-first) * chg_two);

     }

 }

}

 

OUTPUT

Enter total energy used in kilo watts                                                                                                          

5555                                                                                                                                          

Total charge for 5555 kilo watts of energy is 818.25

Explanation:

The program is designed to take user input but does not implements validation for the user input.

The program works as follows.

1. Inside main(), the user enters the energy consumed in kilo watts.

2. This is stored in the integer variable, p.

3. The method bill_calculator() is called which accepts the value of p as a parameter.

4. If the energy used is 500 or less kilo watts, charges are different. While for the amount of energy consumption for more than 500, charges are different.

5. The charges for both, 500 and less and more than 500 are stored in double variables.

6. The if-else statements are used to calculate the total charge based on the amount of power used.

if(e <= 500)

     {      

         total = (e * chg_one);

     }

     else if(e > 500)

     {

         total = ( first * chg_one);

         total = total + ((e-first) * chg_two);

     }

7. Since c# is an object-oriented programming language, any method outside main() is called using the object of the class. All code is written inside the class.

8. Next, the total charge is displayed by calling the bill_calculator() method through the object of the Program class.

9. The main() function has only void return type and hence, no value is returned.

7 0
3 years ago
You plan to use the Fill Down feature on a formula and you need to keep a cell reference the same. Which one of the following fo
viva [34]
You have to use this format for example $A$2
The format for absolute reference is designated with a dollar sign ($). If both column and, put a dollar sign before and in between the row and column. By doing this, column and row do not change when copied.
3 0
3 years ago
.…………….. Are devices that routepackets of data between two or more networks.
Masja [62]

Answer: Routers

Explanation:

Routers are the device that route packets of data between two or more networks as, core router is that which transmitted data from the other router and route packets based on the network information layers and can forward the other packets based on the data link layers information, the layer on which the bridges are operated.

8 0
4 years ago
Read 2 more answers
Can you see what movie you went to on yout credit card history
KatRina [158]
The answer is no
-hope this helped-

3 0
4 years ago
Read 2 more answers
Other questions:
  • When defining an array of class objects, how do you pass arguments to the constructor for each object in the array?
    5·1 answer
  • Which form of malware contains hidden code that is triggered by meeting or reaching a specific condition? (A) Trap door (B) Viru
    12·1 answer
  • To hide gridline when you display or print a worksheet
    14·1 answer
  • Many of the internal OS services are provided by the ___________ module, which contains the most important operating system proc
    8·1 answer
  • If you need to provide a storage server with fault tolerance through the use of multiple paths between the server and the actual
    14·1 answer
  • A virus that is triggered when certain logical conditions are met, such as opening a file or starting a program a certain number
    10·1 answer
  • Bob gets an e-mail addressed from his bank, asking for his user ID and password. He then notices that the e-mail has poor gramma
    6·1 answer
  • David bought 5.2 pounds of oranges for $1.20 per pound . how much did david spend ..............................................
    12·1 answer
  • What's the function of a cyclebin​
    14·1 answer
  • How many accelerometers are there in an IRS system?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!