Question

In: Computer Science

Why wont my java program print out anything past "please enter a group of at least...

Why wont my java program print out anything past "please enter a group of at least 5 integers"?

import java.util.Scanner;

public class MyStatistics {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       Scanner sc=new Scanner(System.in);
       System.out.println("Please enter a group of at least 5 integers.");
      

       String count_val = sc.nextLine();
       int[] int_array = new int[5];
       int sum_val = 0;
       int mean_val = 0;
       System.out.println("Your input has " + count_val.split(" ").length + " numbers");
      
       //Input 5 Numbers
       for(int x = 0; x < 10; x++){
       int_array[x] = sc.nextInt();
       }
      
      
       //Find the sum
       for(int x = 0; x < 10; x++){
       sum_val = sum_val + int_array[x];
       }

      

       //Find the average
       for(int x = 0; x < 5; x++){
       mean_val = sum_val + int_array[x];
       }
      
      
       System.out.println("The sum is: " + sum_val);
       System.out.println("The mean is: " + sum_val / 5);
      
      
   }
      
  
}

Solutions

Expert Solution

import java.util.Scanner;

public class MyStatistics {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       Scanner sc = new Scanner(System.in);
       System.out.println("Please enter a group of at least 5 integers.");

       String count_val = sc.nextLine();
       int[] int_array = new int[5];
       int sum_val = 0;
       int mean_val = 0;
       System.out.println("Your input has " + count_val.split(" ").length + " numbers");

       // Input 5 Numbers
       // here your iterating 10 times because of that it is expecting 10 numbers
       //for (int x = 0; x < 10; x++) {
       for (int x = 0; x < 5; x++) {
           int_array[x] = sc.nextInt();
       }

       // Find the sum
       // here your iterating 10 times because of that it is expecting 10 numbers
       //for (int x = 0; x < 10; x++) {
       for (int x = 0; x < 5; x++) {
           sum_val = sum_val + int_array[x];
       }

       // Find the average
       for (int x = 0; x < 5; x++) {
           mean_val = sum_val + int_array[x];
       }

       System.out.println("The sum is: " + sum_val);
       System.out.println("The mean is: " + sum_val / 5);

   }

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

Write a complete Java program to print out the name bob
Write a complete Java program to print out the name bob
Please finish this code and make it work. This is my homework and my professor wont...
Please finish this code and make it work. This is my homework and my professor wont allow me to change the code in main, it's a set of huge numbers need to sort by radixsort with bit operation. #include <iostream> using namespace std; void radixLSD_help(int *items, int length, int bit) {    // – Count number of items for each bucket.    // – Figure out where each bucket should be stored (positions // of the first and last element...
In java coding, write a program that will print out a representation of a “W” using...
In java coding, write a program that will print out a representation of a “W” using a character that a user provides.
Write a Java program that accepts a sequence of commands and print out the number of...
Write a Java program that accepts a sequence of commands and print out the number of successful insertions, the number of successful deletions, the number of successful searches (through the “find” command), the number of items remaining in the list after executing all commands and the final contents of the list. Three commands that will be taken as inputs are “insert”, “delete” and “find”. Input Line 1: The number of transactions m on the list, where 1  m 200. Line 2...
Write a Java program that directs the user to enter a single word (of at least...
Write a Java program that directs the user to enter a single word (of at least four characters in length) as input and then prints the word out in reverse in the pattern shown below (please note that the spaces added between each letter are important and should be part of the program you write): <Sample Output Enter a word (at least four characters in length): cat Word must be at least four characters in length, please try again. Enter...
Cant figure out why my out is wrong for my c++ program. for example if the...
Cant figure out why my out is wrong for my c++ program. for example if the initial value is 100, the intrest rate is 10%, and it takes 6 months for maturity the output should be $105 but instead it outputs 101.657 please help. #include <iostream> #include <cmath> using namespace std; struct account { double balance; double interest_rate; int term; }; void info(account& accountinfo); int main(void) { double calc1, calc2, calc3; account accountinfo; info(accountinfo); calc1 = accountinfo.interest_rate / 100; calc2...
Write java program that will ask for the user for 2 input lines and print out...
Write java program that will ask for the user for 2 input lines and print out all words that occur 1 or more times on both lines (case sensitive). Write this without arrays and method. Here is a sample run: <Output> Enter two lines to process. The quick brown fox jumps over a lazy dog The fox hound outruns the lazy dog The words that occur on both lines are: The fox lazy dog
I need original java code that completes this program and gets it to print out results...
I need original java code that completes this program and gets it to print out results just like in the example. Also please upload answer in a word document format only. Implement both linear search and binary search, and see which one performs better given an array 1,000 randomly generated whole numbers (between 0-999), a number picked to search that array at random, and conducting these tests 20 times. Each time the search is conducted the number of checks (IE...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to...
Java Program 1. Write a program that asks the user: “Please enter a number (0 to exit)”. Your program shall accept integers from the user (positive or negative), however, if the user enters 0 then your program shall terminate immediately. After the loop is terminated, return the total sum of all the previous numbers the user entered. a. What is considered to be the body of the loop? b. What is considered the control variable? c. What is considered to...
Please write the code JAVA Write a program that allows the user to enter the last...
Please write the code JAVA Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. A sample output is: Candidate      Votes Received                                % of Total Votes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT