Java Arrays - Count Above / Below Average

May 7, 2014

I have to write a program that takes an array of grades and calculate the average and then count the number of grades that are above average and also count the number of grades that are below average. This is what I have so far, it calculate the average and tells me how many are above average... where and how do I get to count how many are below average

public class arrays{
public static void main(String[] args) {
final int grades = 5;
double[] numbers = new double[grades];
double sum = 0;

[Code] .....

View Replies


ADVERTISEMENT

Student Grades For Three Exams And Average In Arrays?

Nov 12, 2014

For my lab this week I have to print out four arrays. The arrays have to be 5 units long. The first three arrays are the student's exam grades for exam 1, 2 & 3 and the fourth array should be the average for each student's three tests. The program should ask the user to input the grades in and then the program should compute the average. For example the program should print this if these are the exam grades the user imputs:

Exam 1 Exam 2 Exam 3 Average
65 79 80 74.66
79 82 59 73.33
99 100 98 99
and so on.......

I thought I wrote the program perfectly and when I compile it there are no errors but when I run it, it only lets me input the numbers for the first three students and then prints out something so strange.

here is my program:

public class Lab9{
public static void main(String[] args){
java.util.Scanner input = new java.util.Scanner(System.in);
int i, sum;
double avg;
sum = 0;
int A[ ] = new int [5];
int B[ ] = new int [5];
int C[ ] = new int [5];
double avg1[ ] = new double[5];

[code]....

View Replies View Related

Calculating Average Of Two Arrays - Calculation Coming Out Incorrect

Oct 8, 2014

I am working on an assignment, and I have come up with a program that runs, but it does not run correctly. This is the assignment:

Write two overloaded methods that return the average of an array with the following headers:

public static int average(int[] array)
public static double average(double[] array)

Write a test program that prompts the user to enter ten double values, invokes this method and displays the average value.

When I run it my averages are coming out incorrect, and I am not sure why. I have tried moving and rearranging things and nothing is working.

Java Code:
public static int average(int[] array) {
int sum = 0;
int average = 0;

[Code].....

View Replies View Related

I/O Arrays - Count Number Of Repetitiveness In String For The Number

May 19, 2014

//read the file
//make the numbers 1 string line
//count the number of repetitiveness in the string for the numbers
//display four lowest ones

import java.io.*;
import java.util.*;
public class Lottery2

[Code] ....

when I run it the array gets sorted but how do i keep the data in other words

what it is supposed to do is grab numbers from a file, and give me the lowest 4 numbers back. I know the numbers using the array but how do i pull out the lowest 4 and keep the data true no matter what numbers or how many of them are in the file.

View Replies View Related

Using Count Element Method To Count Occurrence Of Characters In Array

Jun 30, 2014

I have an array with the following characters {'E', 'L','E','P','H','A','N','T','P','O'}

now, I need an array that will store the first array such that only the occurence occurs e.g {'E','L','P','H','A','N','T','O'} Notice that the characters 'E' and 'P' occur twice and as a result were not repeated the second time in the new array.

How would one go about this using the counting elements technique?

I tried this but not sure how to use the counting elements technique.

char [] arr = new char{'E', 'L','E','P','H','A','N','T','P','O'};
char[] bucket = new char[(arr[0] * arr.length)];
for (int i = 0; i < len; i++)
bucket[arr[i]]++;

View Replies View Related

Java Odd And Even Average

Apr 22, 2014

In the class, you will have three instance variables,

1) array to hold the numbers,
2) the odd average, and
3) the even average.

The constructor should accept as input the array from the tester class and assign it to the instance variable. You should then have a method, findAverage, that will read the array and then calculate the average of the even input values and the average of the odd input values. (Hint: You can use % (mod) to determine if a number is even or odd). Your program will need a getOddAverage and a getEvenAverage method.

public class oddEvenAverage {
int [] myArray = new int[10];
public double oddAverage;
public double evenAverage;
public oddEvenAverage(int number){
int myArray = number;

[Code] .....

What am i doing wrong here? I can't get it working!

View Replies View Related

Java Calculating Mean Average

Feb 21, 2014

I am trying to do the following java assignment and every thing seems to work fine except when I put a number<4 or >10 it prints both "Invalid grade!"

"You didn't enter any data!" what I wanted is to print only "Invalid grade!" I tried to fix it but I couldn't.

Create a program that asks for results of exams and calculates the mean average of the grades. Grades are floating point numbers between 4 and 10. Program asks for grades until a negative number is typed. If user gives a grade other than a number between 4 and 10, the text "Invalid grade!" will be printed on screen and program asks for another grade. Finally the program prints the number of inputted grades and their mean average on screen as shown in the example print. If no grades were inputted, the notice "You did not input any grades." is the only thing printed on screen.

A double type variable is to be used to store the value of the average.

Program is written to a class called Average.

Example output

Program calculates the average of inputted grades.

Finish with a negative integer.

Input a grade (4-10): 5
Input a grade (4-10): 6,5
Input a grade (4-10): 7,5
Input a grade (4-10): 7
Input a grade (4-10): 0
Invalid grade!
Input a grade (4-10): -4
4 grades inputted.
Average of the grades: 6.5

Java Code:

import java.util.Scanner;
public class apples {
public static void main(String[] args)
int inputNumber=0;
int sum;
int count;
double average;

[Code] .....

View Replies View Related

Java Count Up Timer

Mar 6, 2014

How to do a count up timer in java? like "0:00:00" hh:mm:ss

View Replies View Related

How To Count 1st Duplicates Value In Array By Using Java

Apr 12, 2015

I have taken array int[] a = {33,33,5,5,9,8,9,9};

In this array so many values are duplicates means 33 comes twice & 5 also comes twice & 9 comes three times. But I want to count the first value which is duplicate means 33 is first value which comes twice so answer would be 2.

I try:

public class FindFirstDuplicate {
public static void main(String[] args) {
int c=0;
int[] a = {33,33,5,5,9,8,9,9};
outerloop:
for(int i = 0; i < a.length; i++) {

[code]....

Output:

33
Count: 1

View Replies View Related

Test Score Average Program In Java

Jun 16, 2014

I'm working on a homework assignment and I keep getting a compiler message this is the message

GradesAverage.java:44: error: variable totalgrade might not have been initialized
System.out.println("Over all you have " + totalgrade);
^
1 error

The homework is this Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test stores and the letter grade that is assigned for the test score average. Use the grading scheme in the following table:

Test Score Average Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F

This is my code

import javax.swing.JOptionPane; // Needed for JOptionPane class
import java.util.Scanner; // Needed for the scanner class
public class GradesAverage
{
public static void main (String[] args)

[code]....

View Replies View Related

Efficient XML Parsing For Count Using Java Hashmap?

Aug 20, 2014

I am kind of new to Java. I have a query.. look at it. Have an xml like

<ProductList>
<Product Quality='Good' color='Blue'>
<Details ItemID='1001'/>
</Product>
...
..
</ProductList>

The <Product> tags can run into hundreds or thousands. Quality can have values like Good, Bad, Damaged. Color can also have various values (Blue, Red ..)

ItemID can repeat or can be different. So I want group by ItemID->Color->Good count or BadCount and TotalCount as below.

I want to get a sum like

<ProductList>
<ProductType ItemID="1001">
<Product_Detail CountGood="1" CountBad="2" CountTotal="3" Type="Blue"/>
</ProductType>
...
...
</ProductList>

I think using Hashmaps (Hashmap1 for ItemID, Hashmap2 for color, Hashmap3 for quality) may do the work. But I have to parse the xml number of ItemID's multiply-by number of colors multiply by various colors times for this.

Any better algorithm is there in performance perspective using Java.

View Replies View Related

Count Comparisons In Java Quick Sort

Oct 3, 2014

I have to count the comparisons in the quick sort. I have done it by using a global variable. But I am stuck in doing it recursively.

This is my code.

import static java.time.Clock.system;
import java.util.Arrays;
public class test {
/**
* The swap method swaps the contents of two elements in an int array.
*
* @param The array containing the two elements.
* @param a The subscript of the first element.
* @param b The subscript of the second element.
*
*/

[Code] .....

View Replies View Related

Calculating Average Of Two Ints And Converting To Double In Java?

Oct 31, 2014

how to use Java and for my coursework I have been asked to construct an application that will read in the exam mark and coursework mark and then print out to 1 decimal place the average of the coursework and exam mark. When I submit it to the coursework submission system it says it's incorrect.

The answer that it's asking for is the answer that my code produces (ex = 71 cw = 40 mark = 55.5) But for some reason it says this when I submit it:

-#### << Differences between expected (<) your answer (>) >> ------------
1c1
< ex= 91 cw = 80 mark = 85.5
---
> ex = 71 cw = 40 mark = 55.5
-------------------------------------------------------------------------

Check the above output for why this attempt failed And when I change the ex to 91 and cw to 80 it asks for > ex = 71 cw = 40 mark = 55.5 again.

class Main
{
public static void main( String args[] ) {
int ExamMark=71;
int CourseworkMark=40; 
double cost = (double)(ExamMark + CourseworkMark) / 2;
  System.out.printf("ex = " + ExamMark + " cw = " + CourseworkMark + " mark = " + cost);
System.out.println();
  }
 }

View Replies View Related

Java Program To Count Each Repeated Letters In Given String?

Jan 12, 2014

for example if the given string is: The world is running java technology?

Ans:
T is =2
h is=2
e is=2
w is=1
n= 4

like wise i need out put of the program?

View Replies View Related

Java Program Using Nested Loop To Compute / Display Average Of Test Results For Each Experiment

Apr 2, 2015

Four experiments are performed, each consisting of six tests. The number of test results for each experiment is entered by the user. Write a Java program using a nested loop to compute and display the average of the test results for each experiment.

You can run the program by entering the following test results:

Experiment 1 results:23.231.516.927.525.428.6
Experiment 2 results:34.845.227.936.833.439.4
Experiment 3 results:19.416.810.220.818.913.4
Experiment 4 results:36.939.549.245.142.750.6

View Replies View Related

What Is The Difference Between Regular Arrays And Multi Dimensional Arrays

Jun 28, 2014

I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff.

View Replies View Related

In Java Can Do Arrays With Variables?

Apr 7, 2014

So like, in lua programming language you can do things like,

Array = {1, 2, 3, abc = 5, efg = {123, 456, 789, hij = {"tests","works!"}}, hij = true}

Array[1] = 5

Array[3] = true

Can you do atleast something like this in java or?

I would like to do this because if let's say I was making a game, I could define what tiles are passable and which are not and then their location or something, so like this:

//p (passable) stands for if possible to walk on
//c stands for tile image
t = ["grass.png","water.png","chest.png"]
Tiles = [
[p = false, c = t[1], x = 3, y = -2 ],
[p = true, c = t[0], x = 4, y = 3 ],

[Code] ....

Or something...

View Replies View Related

Java - Private Arrays / Integers?

Jan 16, 2015

I have a project for a class where I'm supposed to be something with private arrays and private integers and I still don't understand the point of private anything within java. if I want to change a variable I'll change it. if I want it to stay the same I'll leave it the same. so what point is all this private/public nonsense unless I'm trying to stop hackers or something?

View Replies View Related

Reverse Numbers Using Java Arrays

Feb 27, 2014

I am trying to do this assignment but I can't get the needed output. Create a program that asks the user how many floating point numbers he wants to give. After this the program asks the numbers, stores them in an array and prints the contents of the array in reverse order.

Program is written to a class called ReverseNumbers.

Example output

How many floating point numbers do you want to type: 5
Type in 1. number: 5,4
Type in 2. number: 6
Type in 3. number: 7,2
Type in 4. number: -5
Type in 5. number: 2

Given numbers in reverse order:
2.0
-5.0
7.2
6.0
5.4

My code:

import java.util.Scanner;
public class apples {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
double[] numbers;
System.out.print("How many floating point numbers do you want to type: ");

[Code] .....

View Replies View Related

Getting Error On Java Code Using Parallel Arrays

Dec 1, 2014

This is my code.

public class PA9 {

public static void main(String[] args) throws FileNotFoundException {
// create data file to read from
File inf = new File("cityPopulationData.txt");
//Create a file to write out to.
PrintWriter fileOut = new PrintWriter("output.txt");

[Code] .....

This is my error

Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at PA9.getData(PA9.java:35)
at PA9.main(PA9.java:22)

View Replies View Related

Getting Error With Java Code - Using Parallel Arrays

Dec 1, 2014

Write a Java program to read from the data file, find the city with the highest population based on the 2010 census data, the city with the highest population growth from 2010 to 2013, the city with the lowest population growth from 2010 to 2013, and the city with the highest density (number of persons per sq. mile).

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;

[code]....

View Replies View Related

Java Arrays - Entering Lists Only Let To Enter 2 Numbers?

Oct 9, 2014

I am trying to write a code that allows you to input 2 lists and it tells you if they are identical or not. However, when I enter my fist list I can only enter two values and then it asks for the next list. How would I fix this to allow me to enter more than two values?

Also, If the second list is different it has me enter more values that list one.

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
  // Enter values for list1
System.out.print("Enter list1: ");
int size1 = input.nextInt();
int[] list1 = new int[size1]; 
for (int i = 0; i < list1.length; i++)
list1[i] = input.nextInt();
  // Enter values for list2
System.out.print("Enter list 2: ");

[code]...

My output looks like this:

Enter list1: 1
2
Enter list 2: 2
3
2

Two lists are not identical

View Replies View Related

Adding Data File Into Two Separate 2D Arrays In Java

Apr 27, 2014

I am having some trouble with a Java program. I have a txt data file, which I will display, that I need to add into two separate arrays. The text file is 8 lines long that is supposed to go into two separate 4x4 matrices. A little background info on this program, reads in two arrays, compares them and outputs the largest elements of the same index and outputs them in a separate array. I somehow cannot seem to figure out how to do this. My code is below:

Data File:

2 7 6 4
6 1 2 4
9 7 2 6
8 3 2 1
4 1 3 7
6 2 3 8
7 2 2 4
4 2 3 1

Code:

public class prog465a {
public static void main(String[] args) {
Scanner inFile = null;
try {
inFile = new Scanner(new File("prog465a.dat.txt"));

[Code] .....

View Replies View Related

Java Program That Specifies Three One-dimensional Arrays Names Price / Amount And Total

Dec 2, 2014

Recently I have missed a few weeks of my class due to family emergencies. Because of this I have missed very important lectures. My professor has assigned me the following assignment:

Prices Write a Java program that specifies three one-dimensional arrays names price, amount, and total. Each array should be capable of holding 10 elements. Using a loop, input values for the price and amount arrays. The entries in the total array should be the product of the corresponding values in the price and amount arrays. After all the data have been entered, display the following output:

Total Price Amount

==== ==== ======

Under each column heading display the appropriate value.

I know how to display everything using printf, how to create the actual arrays and define the array size, but I am confused on how and what loop to use and how to construct it. This is what I have managed to write up so far:

import java.util.Scanner; // Imports the Scanner class
import java.text.DecimalFormat; // Imports the DecimalFormat class

public class Prices
{
public static void main(String [] args)
{
double[] price = new double[10];
double[] amount = new double[10];
double[] total = new double[10];

// Create a new Scanner object
Scanner keyboard = new Scanner(System.in);
} //End of main method
} // End of public class

View Replies View Related

GPA And Average Program

Mar 25, 2014

I am new on this and I will be working in a gpa and average program. This is my code so far: Every time that I try to add the gpa part it gives me errors or just duplicates whatever I've in average and displays it in gpa

/**
* This program shows a database of students in a school.
* It gathers information as name, classes, grades, and calculates average and gpa average.
*
*/
import javax.swing.JOptionPane;
 
[code]....

View Replies View Related

Compute Average Of The Sum

Dec 30, 2014

I'm having trouble compiling this program. It is supposed to compute the average of the sum:

import java.util.Scanner;
public class ComputeAverage
{
public static void main(String[] args) {
Scanner bucky = new Scanner(System.in);
double fnum;
double snum;

[Code] ......

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved