Saving Number Of Chart In Array To New Array

Jan 15, 2014

just started programming in Java. My goal in this part of code was to read out the first array, while saving the number of the chart in the array to a new array.

first question: is the code clean and the method correct?

2nd question: i get an error when i try to print the newInt Array for no apparent reason.

Java Code:

public class viereinsdiezweite {
public static void main(String[] args){
int[] newInt = new int[20];
int specialInt = 3;
int[] bigInt = new int[]

[code]....

View Replies


ADVERTISEMENT

Print Array Asterisk Bar Chart

Jul 6, 2014

I am trying to get this program to take 5 integers from a user and print a bar chart made of asterisks. The only way I've been able to access the values stored in the array is when my loops are nested, but this keeps my output from printing the way I would like it to.

It prints:
Enter a number:
2
**
Enter a number...and so on

I want it to take the values say(2,3,5,8,4) and do this:
**
***
*****
********
****

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int[] barArray = new int[5];
for(int i =0; i < barArray.length; i++){
System.out.println("Enter a number: ");
barArray[i] = in.nextInt();
for(int j = 0; j < barArray[i]; j++){
System.out.print("* ");
}System.out.println("");
in.close();
}
}

View Replies View Related

Monthly Temperature Chart Of Two Places - Array / While Loops

May 29, 2014

I started taking a java programming class javascript eclipse The program says it wants a monthly temperature chart of two places..Declare an array of values for Blueville temperatures and another array for Orlando temperatures. Then, use what you have learned to produce a program to output the following table:

Blueville Monthly temperatures

jan feb mar apr may jun jul aug sep oct nov dec

3 3 5 10 16 20 24 23 16 10 5 3

Orlando Monthly Temperatures

jan feb mar apr may jun jul aug sep oct nov dec

14 16 12 23 24 25 27 30 25 22 17 15

The warmest month in Blueville is _______

The warmest month in Orlando is ________

The month with the greatest temperature spread is __________

View Replies View Related

Create 2D Array Out Of CSV File And Find Number Of Elements To Determine Array Size

Mar 24, 2015

I am taking the Class Algorithms and Datastructures and got an assignment for Lab that really throws me off. The goal is to create an Array out of a given CSV file, implement several Methods that get the size of array, etc.

I am still stuck in the first part where the CSV has to be imported into the Array. My problem is that I need a mechanism that figures out the needed size for the Array, creates the array, and only then transfers the data from the CSV.

The list consists of the following wifi related values:

MAC-Adress, SSID, Timestamp, Signalstrength.

These are on the list, separated by comma. The Columns are each of these, and the rows are the four types of values making up the information on a certain wifi network.

The catch is, we are not allowed to use any of the following:

java.util.ArrayList
java.util.Arrays
and any class out of java.util.Collection.

So far I used the BufferedReader to read in the file and tried to implement the array, but I get an arrayindexoutofboundsexception.

Below is my Code (Its still an active construction zone):

public class WhatsThere {
public WhatsThere(String wifiscan) throws IOException {
}
public static void main(String[] args) throws IOException {
// WhatsThere Liste = new WhatsThere(String wifiscan);
String[][] arrayListe = new String[0][0];

[Code] ....

View Replies View Related

Java Number Spiral - Creating 2D Array With Given Input Of Dimensions Of Array

Aug 3, 2014

I am working on a problem where i have to create a 2d array with given input of the dimensions (odd number) of array, along with a number within the array and to then print out all of the numbers surrounding that number.

Anyway, i am working on simply making the spiral, which should look like the one below.

n = 3

7 8 9
6 1 2
5 4 3

where the 1 always starts in the center with the 2 going to the right, 3 down, then left etc. etc. I was able to create the code by starting on the outer edges rather than the center and working my way to the middle, however my code always starts from the top left and goes around to the center where it needs to start from the top right. I am having trouble altering my code to meet this criteria. This is what i have thus far.

import java.io.*;
public class Spiral
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the number of elements : ");
int n=Integer.parseInt(br.readLine());

[Code] .....

View Replies View Related

Saving Student Grades In Int Array - Pass Rate 50

Apr 8, 2014

prompts user for the grades of each of the students and saves them an int array called grades. Your program shall check that the grade is between 0 and 100. program should then check if the grade is equal to or greater than 50, where 50 is the pass rate.

A sample output :

Enter the number of students: 3
Enter the grade for student 1: 55
Enter the grade for student 2: 108

Invalid grade, try again...

Enter the grade for student 2: 56
Enter the grade for student 3: 57

The average is 56.0
The maximum is 57
The minimum grade is 55
The number of fails is 0
The number of passes is 3
..

I am quiet stuck on this one.

View Replies View Related

Find Slot Number In Array?

Jan 30, 2015

what I needed to know to complete the lesson, but now it just tells me what the output should be and I have to research the information on my own. anyways, here is my code from the previous lesson:

import java.util.Random;
import java.util.Scanner;
public class tnArray {
public static void main(String[] args) {
int [] array;

[code]....

Now I have to change it so that instead of counting the number of times a number will appear in the array, I must output which slot in the array the number is in.

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

Print 2 Largest Number In Array

Apr 1, 2014

Thought process : Sort the array and print the last 2 element of any given array.

Note /| Should not use any inbuilt Array.sort()

Java Code:

//Write a code to print the 2 largest numbers from the given Array {2,8,10,5,9}

package arrays;
public class biggest2numbers {
public static void main(String[] args) {
int[] A = {2,8,10,5,9};
//Declaring 2 variable
int Max1,
Max2;

[Code] .....

View Replies View Related

Removing Negative Number From Array

Jul 20, 2014

Ask the user to enter a sequence of at most 20 nonnegative integers. Your program should have a loop that reads the integers into an array and stops when a negative is entered (the negative number should not be stored). Invoke the average method to find the average of the integers in the array (send the array as the parameter).

how can I remove the negative number from the array and calculate the average of the posive elements without the negative ones? This is my code so far...

import java.util.Scanner;
import javax.swing.JApplet;
public class Parameters
{
//-------------------------------------
//Calls the average and minimum methods
//with different numbers of parameters

[code]....

View Replies View Related

Move All Of Number 7 To Front Of Array

Jan 24, 2015

I'm using Dr.Java and doing a numbershifter lab. I have to create a random array of number from 1-10. Then move all of the 7s to the front of the array. The order of the other numbers is not important as long as all numbers follow the group of Lucky 7s. Files needed Numbershifter.java and numbershifterrunner.java. All data is random.I have done the following:

public class NumberShifter
{
public static int[]makeLucky7Array( int size)
{
int [] newRay = new int[size];
for( int i=0;i<newRay.length; i++)
{
newRay[i] = (int)Math.round(Math.random()*10+1);

[code]....

It's adding to many 7s in the front of the array.

View Replies View Related

Find Biggest Number From Array

Jun 26, 2014

I have 2 arrays in random order of 10 numbers.I need to find the biggest number from array A and B and then when its on a screen second thing is to multiply those numbers by 2.

import java.util.Random;
public class Projektas {
public static void main(String arng[]){
int i,j;
int A[] = new int [10];
int B[] = new int [10];;

[code]..

View Replies View Related

Multiply Every Number In Array By 2 And Print It Out

Nov 2, 2014

My assignment is to write some code that will multiply every number in an array by 2 and print it out. This is using a site zyante which is a interactive online book kind of thing.

I have tried For (i=0; I < 8; i++) with like userVals = userVals * 2) }

And it doesn't like that so i'm guessing i am no where close to right. The chapter doesn't give me any example of doing anything close to this so i am completely lost on what i have to do.

This is the program :

import java.util.Scanner;
 public class NegativeToZero {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
final int NUM_ELEMENTS = 8; // Number of elements

[Code] .....

View Replies View Related

Character Converting Into Number In 2D Char Array?

Mar 29, 2014

I'm trying to convert all letters in a 2D char array into number. As results, I want a = 0, b=1, c=2, ... z=25.

Then, I tried this as part of my code:

char [][] letters = {{'i', 'u'}, {'a', 'g'}, {'e', 'k'}};
for (int i = 0; i < letters.length; i++) {
for (int j = 0; j < letters[i].length; j++) {
if (letters[i][j] >= 'a' && letters[i][j] <= 'z') {
letters[i][j] = (char) ((letters[i][j] - 'a') + '0');
}
}
}

The result of my code is not what I expected before.

From 'a' to 'j', it worked well. But, from 'k' until 'z' it didn't print expected number.

What's wrong with my code and what is the correct way to fix it?

View Replies View Related

How To Find How Many Times A Number Appears In Array

Dec 7, 2014

This is my code up to now and I can't do anything to make it work. I want it to tell me how many times the number 3 appears, and the last position it was in. I am getting errors like"Cuanto.java:88: getPosition(double[],double) in Cuanto cannot be applied to (double) ....

a = getPosition(a);" and unreachable statements, and value not found. It's all over the place every time I make a change to it.

Java Code:

public class Cuanto {
static int getPosition(int count,double listOfValues[],
double targetValue) {
int a = 0, i;
for (i=0; i < listOfValues.length; i++) {
if (listOfValues[i] == targetValue) {
a++;

[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

Array / List Of Ints Contains Specific Number

Jan 24, 2014

I've been trying to make a list of numbers/ints and later on check that list for a specific number.

View Replies View Related

Random Generate Secret Number Into Array

Apr 1, 2014

Trying to generate random integers, based off user-input for amount of integers, and then sort them into an array. The problem is that the second method needs to be int[] but I cannot figure out what to make the return result. The instructions say it needs to be an int[] in the UML diagram, so I know it's not supposed to be void.

Java Code:

public void generateNewSecret() {
Random rand = new Random();{
for (int i=0; i<numDigitsSet; i++) {
secretNumber[i]= rand.nextInt(10);
System.out.println("" + secretNumber[i]);

[Code] .....

View Replies View Related

How To Count Frequency Each Number In Array Occurs

Dec 14, 2014

I'm trying to write a program that counts the number of times each number in an array occurs. In theory I understand how it work, you take the first element in the array, compare it again the rest of the array and any time it occurs in the array you increment a counter by 1. Then move onto the next element A[1] and so on...

This is what I've done so far :

public static void main(String[] args) {
int[] array = {5,6,2,5,2,2,0,1,6};
int count = 0;
for(int i = 0; i <array.length; i++) {
int val = array[i];
for(int j = i+1; j<array.length; j++)

[Code] .....

I think I'm on the right track as it correctly prints out the frequency of the first 3 elements, but I'm definitely going wrong somewhere as it just doesn't do it right after that!

View Replies View Related

Returning Index Of Last Occurrence Of A Number In Array

Apr 16, 2014

I'm making a program with several functions for an array of integers, one being to find the last occurrence of a given integer and returning it. The problem is that the method is returning -1 for every input, even though it's only supposed to do so for numbers not in the array. Here's the part of my code with the sections I'm having an issue with:

Driver

import java.util.Arrays;
public class ArrayMethodsDriver
{
public static void main(String[] args) {
int[] a = {7,8,8,3,4,9,8,7};
System.out.println("Last index of 8: " + ArrayMethods.findLast(a, 8));
System.out.println("Last index of 2: " + ArrayMethods.findLast(a, 2));

[Code] ....

As you can see, I'm testing 8(which should give a 6) and 2(which should give -1 because it's not in the array), and 4(which should give 4). The print statements all say -1.

View Replies View Related

ArrayList - Scan Array For Largest Number

Mar 24, 2014

I need to create a program that uses ArrayList to store integers the user inputs, then scan the array for the largest number. I would also like the user to be able to exit this loop if the number 0 is entered.

As you can see below, I'm not sure how to correctly exit the do-while loop. I found this on another forum, but it does not work.

Java Code:

import java.util.*;
public class array {
public static void main(String [] args){
ArrayList<Integer> list = new ArrayList<Integer>();

[Code] ....

View Replies View Related

Java - Find Number In Given Array Of Integers

May 2, 2014

I wrote this simple piece of code to find the number in the given array of Integers. The program works fine although it shows a couple of errors when i modify it a little bit.

public class DemoLabel{
public static void main(String [] args){
int[][] arrofInts={
{32,45,67,87},
{23,44,55,66},
{12,47,87,56},
{23,44,12,78}

[Code] .....

In the disp() method,Suppose i only want to pass two arguments i.e disp(i,j) given that searchFor variable is visible in the entire class but when i use disp(i,j) i get the following error

DemoLabel.java:38: error: cannot find symbol System.out.println("The number "+searchFor+" is at the location"+i+" , "+j);
^
symbol: variable searchFor
location: class DemoLabel

So i decided to declare the

int searchFor
as
public int searchFor

But the compiler threw another error saying that it was a Illegal start of expression

Also,when i add a SOP line after the label search: it shows the error

DemoLabel.java:25: error: undefined label: search
continue search;
^

Although i got the program to work it would be useful if i could understand why it doesn't work with the modifications.

View Replies View Related

Count Number Of Occurrences Of A String In Array List?

Apr 6, 2015

I am trying to count the number of occurrences of a string in an array list. I used the following code:

int count = Collections.frequency(strings, search);

strings is the name of the array list and search is the string that I am trying to count the number of occurrences of. My program compiles correctly, but when I enter the string to search for, I get the following error: "Exception in thread "main" java.lang.NullPointerException at java.util.Collections.frquency(Collections.java:37 18)

Why am I getting this error message and how do I fix it?

View Replies View Related

Random Number Generator To Pick Index From Array?

Oct 31, 2014

Im creating my 2nd project ever and its a hangman game. I created an Array that has 20 different words in it and need to create a function that generates a random number to pick a random index of the array to obviously pick a random word. I cannot figure out the syntax for the life of me.

View Replies View Related

How To Randomly Select A String In Array Based On Corresponding Number

Dec 21, 2014

I'm trying to generate a random word from the array that I have made including the words by making it corresponding with a randomly generated number. So for example, if the number generated is 0, then the word that the person has to guess would be "AUNT". How would I transfer the randomly generated number from one method into the array method to get the word the person has to guess?

Write a program called Word Guessing Game. Open the file FourLetterWords.txt and write the contents into an array of Strings (the file has 87 words in it). Then use a randomly generated number between 0 and 86 to select a word. The player will then try to guess the word selected by the game. The player is allowed 7 tries, if the player does not guess the word on the 7th try he/she losses. Display the letter of the word as they are guessed in the correct order, you will also display the incorrect letters. The game is over when:

- The player completes the word, or guesses the whole word correctly.
- The player does not guess the word in seven tries.
The player must also be allowed to terminate the game.
The game must have at least 5 classes:
- Main Class
- Class to return a random integer between 0 and 86.
- Class to return a populated array of 87, 4 letter words.
- Class to return a character that the player enters from the keyboard.
- Class to display both the correctly guessed letters and the incorrect letters.

My code (it is not complete, my attempt to do what I am trying to do is obviously not working.)

import java.util.Scanner;
public class WordGuessingGame {
public static void main(String[] args) {
final int NUMBER_OF_WORDS = 87;
RandomWordGenerator.random(NUMBER_OF_WORDS);

[code]...

View Replies View Related

Random Number Generator To Pick Index From Array

Oct 31, 2014

I am creating my 2nd project ever and its a hangman game. I created an Array that has 20 different words in it and need to create a function that generates a random number to pick a random index of the array to obviously pick a random word.

View Replies View Related







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