Finding Simple Moving Average With Array

Apr 8, 2014

How can I find out the simple moving average by just using the numbers stored in an array?

View Replies


ADVERTISEMENT

Finding Average Of Multidimensional Array

Mar 2, 2015

public class StuTest {
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args){
int[][] testScores; // [students][tests]
String[] stuNames;

[Code] ....

The method I am having issues with is the "printStudentReport" method. I am trying to calculate the average of a randomly generated number of students and tests. For my "printTestReport" method, I have to calculate the average of the test by test number.

View Replies View Related

Simple Java Game - Moving Icon That Is Controlled Using Keyboard

Apr 1, 2014

I am writing code for a simple java game. The problem I am running into is that I have a moving icon (J button) that is controlled using the keyboard (arrows) and I also have stationary icons (J button). Is there a way to keep the moving icon from passing over the stationary icon? I would like the stationary icon to act like a wall.

View Replies View Related

Make A Simple Platformer Game In Java - Moving Characters

May 24, 2015

I am trying to make a simple platformer game in Java. When I try to move the character I made it only moves over then immediately back

import java.awt.event.KeyEvent;
public class UCC
{
private int xLoc;
private int yLoc;
private int xSpeed;
private int ySpeed;
private double gravity;
private int size;
 
[code]....

View Replies View Related

Array Index OutOfBounds Exception While Moving Creature Through 2D Array

Oct 13, 2014

I am receiving an ArrayIndexOutOfBoundsException for the following code, which moves a creature through a 2D array maze. I have altered the clauses of the first if statement for the four direct methods (north, south, east, and west) multiple times (i.e. x + 1 >= 0 && x > 0 && x - 1 > 0 && x < array.length...etc). However, while the code occasionally runs, more often than that it returns this exception. Catching the exception seems like a poor workaround though if worst comes to worst I'll do that.

I included only the relevant functions of the code:

public boolean goNorth(char[][] array) {
boolean success = true;;
x = getX();
//x = this.x;
y = getY();
//y = this.y;
if ((x - 1 >= 0 && x - 1 < array.length)
&& (y >= 0 && y < array[x].length)) {

[Code] .....

View Replies View Related

Finding A Value In 2D Array

Dec 3, 2014

I have assigned random numbers to an 2D array, and I had to write a method that prompts the user for a number between 100 and 200. If that number is in the array, it should return 1. If not, 0. It only stays 0 though, even when the number matches one of the numbers in the array.

public static int Findit(int[][] numbers, int guess) {
int Findit = numbers[0][0];
int i = 0;
int x = 0;
boolean found = false;
for(i=0;i<numbers.length;i++)

[Code] ....

View Replies View Related

Array Of Objects To Create 3 CDs (music) - Moving Songs?

Oct 17, 2014

Do I need to use inheritance for this type of program? How to move my song list in main to songs and from songs to cd to make 3 separate cd's.

I have 3 classes: main, Cd, and Song. I am having trouble moving the songs from main to the song class and from the song class to Cd.

package p2;
public class Main {
public static void main(String[] args) {
String tempStr;
//array for song names
String [] songNames={

[Code] ....

View Replies View Related

Finding A String In Array

Oct 4, 2014

My current problem is when im trying to choose case 2 and call markItemOnLoan i cant seem to find the title i want after i enter a few. I will include all of my code but i have mentioned what I am currently stuck on :

import java.util.Scanner;
public class Library {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
MediaItem mCall = new MediaItem();
Library call = new Library();// makes instance

[code]....

View Replies View Related

Finding Sum Of Two Dimensional Array

Apr 1, 2014

How to declare a 2 dimensional array of interger of size 10 by 10. and then set every element of the array to 3. After this I need to add up all the element in this array and return the value.

final int ROWS = 10;
final int COLS = 10;
int[][] foo = new int[ROWS][COLS];
for (int i = 0; i < ROWS; i++){
for(int j = 0; i< COLS; i++){
foo[i][j] = 3;
}
}

This is what i have done so far(not 100% if is correct..) but how to add up all the array.

View Replies View Related

Finding Median Of Array?

May 3, 2014

I'm trying to find the median of a set of numbers inputted into an array and I wanted to know how I would pass the array to the median calculator after I use selection sort to organize the numbers.THIS IS THE CODE THAT ORGANIZES THE ARRAY:

public void selectionSort(double[] myArray) {
for (int i = 0; i < myArray.length - 1; i++)
{
int index = i;
for (int j = i + 1; j < myArray.length; j++)

if (myArray[j] < myArray[index])

[code]....

The code that finds the median will only work if the array being used is already organized. How do I pass the new sorted array to the code that finds the median?

View Replies View Related

Finding Minimum Value Of Array

Sep 11, 2014

I'm almost finished with my assignment, I'm just having one small issue. The goal of this assignment is to have a user input as many values they want(up to 10) into a list. I need to store those in an array then figure out the sum of the numbers, the average, the Largest value, and the smallest value. I get everything to print out correct so far except for the Smallest number, it is returning a 0 every time. Here is my code:

import java.util.Scanner;
public class SimpleList{
Scanner in = new Scanner(System.in);
final private static int ARRAY_LENGTH = 10;
private float[] List = new float[ARRAY_LENGTH];
private int count = 0;

[Code] ......

View Replies View Related

Finding Longest Zig-Zag Sequence In Array

Oct 26, 2014

From a given array of positive and negative numbers, I have to find the longest SUB-Array which represents a Zig-Zag sequence...

A Zig-Zag sequence means that one number is possitive, the next one negative, the next one possitive, and so on and so on...

Like this: -1, 4, -5, 6, -9, 2, -9 etc....

So that means, if the array looks like this:

1, 4, -2, -5, 6, -9, 1, -4, 9, -8, 7, 4, -3

the longest sub-array which fulfills the requirement is (the part in bold):

1, 4, -2, -5, 6, -9, 1, -4, 9, -8, 7, 4, -3

and I only need it's length, which in this case is: 8

View Replies View Related

Finding Path Through 2D Array From Top To Bottom?

Apr 20, 2015

I have a 2D array that is of type int[][]. it is populated with 1's and 0's. I need to create a method that allows me to search from the top row finding a possible path to the bottom--the path is a path of connecting cells containing 1. I need to create an array that stores the cells that are needed to be searched. When the search carries out, for each cell stored it needs to check the cells to the left, right, below and above the current cell.

I also need to create a variable to store the current cell. I thought initially it would be an int but it can't be because it needs to hold the the index of the current cell. and any of the cells searched that are an immediate neighbour of the current cell are added to the storage array.

I have these instructions but I am having trouble converting into code

Finding a path through vegetation from the top row to the bottom row: The idea is we will start from a cell in the top row and advance below for as long as we can. Since we are still not done exploring a cell until we have explored ALL it’s vegetation neighbors, we will add the cell to an array of cellsToExplore and only come back to it if the current cell we are examining is fully explored. Here is pseudo-code of the algorithm !

• Create array cellsToExplore (what size should this array be?)!

• Create an integer count that stores the number of cells in cellsToExplore!

• Go through the top row and add ALL vegetation cells to cellsToExplore!

• Create a variable to store currentCell we are exploring and set it to null.!

• while count > 0 do!

- set currentCell to the last cell in cellsToExplore (last cell added to the array).!

- label currentCell as burning vegetation!

- If the currentCell is on the bottom row then we return true (we found the path).!

- if the cell below currentCell is vegetation then add the cell below to the cellsToExplore array.!

- else if cell to the right of currentCell is vegetation then add the cell to the right to cellsToExplore!

- else if cell to the left of currentCell is vegetation then add the cell to the left to cellsToExplore!

- else if cell above the currentCell is vegetation then add the cell above to cellsToExplore.!

- else remove the currentCell from the cellsToExplore (we are done with this cell). !

• Return false!

View Replies View Related

Printing Out Array And Average Of Array

May 2, 2014

So I'm trying to write a program that will take in 5 numbers, store them in an array and then print out the array and the average of the array. Problem is that every time I run my program I get a "ArrayIndexOutOfBoundsException: 5" error and I don't know who to fix it.

public class ConstructorHomework {
final static int size = 5;
static double[] myArray = new double[size];
public static double average;
public void printArray(){

[code]...

View Replies View Related

Finding A String Word In Char Array

Feb 13, 2015

I'm trying to find a word in an array of char.....but I'm stuck. How to formulate the code to step through the array and pick out the word. This is what I have so far...

public static void searchAcross(String string, char[][] puzzle) {
// Gets the number of rows in the matrix
int rowLength = puzzle.length;
//Gets the number of columns in the matrix.
int colLength = puzzle[0].length;

[Code] ....

View Replies View Related

Finding Array Index Number Through For Loop

Jan 29, 2014

int[] a = new int[7];
a[0] = 0;
a[1] = 10;
a[2] = 256;
a[3] = 57;
a[4] = 33;
a[5] = -154;
a[6] = 168;

[code]....

What program needs to find is the most biggest number. It does the job, but another task of the program is to find the index of that number . The second loop should do just that, but for some reason, as the loop goes further, it passes through the if statement even though answer "a[i]" is not equal to "answer". The idea is that if a[i] and answer are equal, the "i" should represent the index number.

View Replies View Related

Finding Duplicate Values In Array List

Jul 8, 2014

I am working on this project that wants me to write a program that inputs 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, display it only if it is not a duplicate of a number already read. The only part I am confused about is how to go about checking for duplicate values that the user may enter. And IF the user does input a duplicate value, it should not be stored again.In addition, the value entered should be printed out after it is entered along side the value that have been previously entered by the user such as:

23
23 45
23 45 67
23 45 67 12
and so on.

I am still fairly new at java programming.

import java.util.*;
public class NumberArray
{
public static void main(String[] args) {
// declare an array with 5 elements

[code]....

View Replies View Related

Finding Lowest Value In Array Using Linear Search?

Apr 5, 2014

I am attempting to find the element that holds the lowest time ( i have used System.currentMillisTime ) in the array using a linear search and to then print the times held by the array in lowest to highest order . While i understand how to do a linear search using user input as the key i am not to sure how to do it by initializing a search key in the program to the lowest number and have little experience in using a search in a program that is not a simply linear search. i have attempted to code this, as seen below, but i know i am definitely wrong and i have tried another of different ways even Array.sort and then a binary search .

static long store_MAX[]; // Now an ‘array’ of ints
static int deptSize; // Holds the length of the buffer
private int shopper_MAX; // Holds the number of items in the buffer

[Code].....

View Replies View Related

Finding Fifty Biggest Numbers In The Array?

Feb 12, 2014

How to find fifty biggest numbers in the array?

View Replies View Related

How To Get Average Of Strings Using Array

Apr 21, 2014

I'm trying to calculate the average of grades that a user puts in. Here is my code so far:

public static void main(String[] args) {
Scanner input = new Scanner (System.in); 
System.out.println("Please enter an array of grades seperated bt a comma.");
input.nextLine();
String arrayOfGrades = "100,50,100";
String[] grades = arrayOfGrades.split(",");
 
[Code] .....

I think I'm on the right track, the only big error I'm really getting is the line: sum += grades[i]. It's saying string can not be converted into a double.

View Replies View Related

Number Closest To Average Sum For Given Array

Oct 19, 2014

Find the numbers which is closest to the average sum for a given array of N (1<=N<=50) of natural numbers. If there are two numbers who meet the requirement, return the smaller of the two.

For example for the array of: 1,2,3,4,5,6 the average sum is 3.5, so both 3 and 4 are the closest to that, but the program has to return 3, because it's smaller than 4.

The array can also contain duplicates. First we type the number of elements in the array, then in each line we add the numbers. Name of the class: Array

**Note**: Create a data structure array and use it.

And this is what they have given to me, I just need to type the code:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Array<E> {
public static int closestNumber( ) {

[Code] .....

View Replies View Related

Array Of Numbers Not Able To Get Correct Average Value

May 26, 2015

I have the following methods:

public static int getSum(int[] data) {
int sum = 0;
for (int i = 0; i < data.length; i++) {
sum += data[i];
}
return sum;

[code]....

The input is the following arary (Its from the Junit test that fails this): [Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE].I get an average of 0.0 when it should be -0.2.

View Replies View Related

Array - The Local Variable Average May Not Have Been Initialized

May 13, 2014

public class Apples{
public static void main (String args[]){
int array[]={21,16,86,21,3};
int sum=0;
int average;
 
[Code] .....

Eclipse: Exception in thread "main" java.lang.Error: Unresolved compilation problem:

The local variable average may not have been initialized

at Apples.main(Apples.java:11)

View Replies View Related

Displaying Random Value Of Integers And Then Finding Missing Integer From Values In Array

Feb 7, 2015

I have a problem where I have to create random integers from 1 to n + 1. When the array is displayed I have to find the missing integer from the values that are displayed and show that value. I have to use O(n^2) and O(n) operations. I have created this code so far but I cannot figure out how to make my values display n + 1. It is only displaying values 1, 2, 3, 4 and 5 in random order. I also cannot figure out how to find the missing value. I have created a boolean displayed statement but can't determine how to use it in this code.

=Java
import java.util.Random;
public class Task6
{
public static void main(String[] args)
{
int[] numbers = new int[7]; //create array of numbers
Random random = new Random();
boolean displayed = false; //boolean value to determine if number was displayed

[code].... 

View Replies View Related

No Compiler Errors / Finds Largest Number In Array But Not Finding Smallest

Oct 19, 2014

A java program to print 10 random numbers between 512 and 1024 and then finds the smallest and biggest numbers from the list using only one loop

class BSLab4d {
public static void main (String[] args){
int[] nums = new int[10];
int largest = nums[0];
int x = 0;
int smallest = nums[0];
int y = 0;
 
[code]....

View Replies View Related

Print Inputted Data - Name / Score And Average Using Array

Aug 22, 2014

Conditions : Need to print all the inputted data(name,score) and the average.

import java.util.Scanner;
public class Case2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] score = new int[5];
String[] name = new String[5];
int ave = 0;

[Code] .....

View Replies View Related







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