I need to make a code that will ask the user for an array size and the numbers that go in the array. Then it must ask for a new size and copy the numbers from the first array and add numbers to fill the new array.
import java.util.Scanner;
import java.util.Arrays;
public class Lab07{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("How many numbers do you want to enter?");
[Code] ....
I can make the first array but I am getting stuck on the second this is what I am getting back
How many numbers do you want to enter?
3
Enter the 3.0 numbers now.
7
1.2
9
These are the numbers you have entered.
[7.0, 1.2, 9.0]
How many numbers do you want to enter?
5
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at Lab07.resizeArray(Lab07.java:27)
at Lab07.main(Lab07.java:18)
Suppose i have a book class and bookArray class.in book class contains four fields name,id ,publisher and author. in bookArray class: book bookArray=new book[20]; i have to save those four fields in the array but after completed the array i should have re-size the array with contains the previous data. How?? I have pass those values from the main class..
I've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.
[ public class Array1 { public static void main(String[] args) { int array [ ] = new int[100]; for (int i = 0; i < array.length; i++) { array[i] = (int) (Math.random() * 26);
I'd like to be able to sort them so that if I want to search for one of the entries, I can then create a function which allows me to sort them by date or even return all the numbers by a given date or day, etc....
However, I'd like to be able to set it up so that each set is "linked" meaning that again that I can search by date and it returns everything at that date.
import java.util.Scanner; public class ColumnSum { public static void main(String[] args) { Scanner s = new Scanner (System.in); int userpick = 0; int sum = 0; int [][] matrix = {{5, 9, 87, 74, 12, 7}, // row 1
[code]...
Right now my code gets all the numbers in a row and adds those up, but I want it to get the numbers in a column and add them instead. The problem is I don't know how to get the userpick (the number that the user picks to determine which column gets added) to be set to that particular column.
package com.arraydemo; import java.util.TimeZone; import java.util.concurrent.TimeUnit; public class ArrayStructures { public long[] theArray; public int arraySize; public ArrayStructures(int size)
I just learned about 2D arrays and am still trying to get a grasp on the concepts. I'm a little confused by how you return all the values in a row to add up and display the sum if the row is entered by the user.
import java.util.*; public class RowSum { public static void main(String[] args) { Scanner s = new Scanner (System.in); int userpick = 0; int sum = 0;
i'm trying to write a program that uses an array to store 10 numbers. The numbers should be randomly generated ( Math.random() ), and they should be between 1 and 100 ( 1 and 100 inclusive ). The program should produce an output like the one below:
Element 1 = 23 ( Odd ) Element 2 = 15 ( Odd ) Element 3 = 32 ( Even ) Element 4 - 10 ( Even ) Element 5 - 99 ( Odd ) Element 6 - 1 ( Odd )
[Code]...
I have written code for this but its only showing me 0's after first number can you check whats wrong with my code. my code is.
class even/odd{ public static void main(String[]args){ int y=0; int z=0; int[] array= new int[11]; for(int x=1; x <array.length ; x++){ array[x]= (int) (Math.random()* 100);
I need a phonebook that allows the user to input up to 100 numbers but stop when they want to. I have the code for the array and input and output. I thought I had the do...while loop correct for asking the user if they want to input another name but its not working, even when you input "N" it still keeps going. Here's my code.
import java.util.Scanner; import java.util.ArrayList; public class PhoneEntry2 { int x; char repeat; final int maxContacts = 100; String[] pNums = new String[100];
I have an assignment that wants me to write a Java function based on induction to determine how many numbers in an array have a value greater than, or equal to, 100.
I have started with:
Java Code:
int recurseHundred (int [] A, int n) { //n is the number of elements in the array. //Base case: if (n == 1 && n >= 100) return A[0]; //Recurse int num = recurseHundred(A, n-1); if (n-1 >= 100) return A[n-1]; else return num; } mh_sh_highlight_all('java');
For a project we have to "shuffle" items in an array using random numbers. We are supposed to generate random numbers and use those numbers to exchange array elements. But I am not sure what that means, "exchange array elements". Does that mean you generate 2 random numbers within the length of the array, and then switch the items at those locations in the array?
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.
"on each step of the loop you can calculate an entire year as opposed to a single month, otherwise you can calculate monthly, but instead of printing, create an array and fill it up with your solutions, then have a second loop where you add them up by dozens to print yearly values, alternatively, have a counter k that adds up to 12, and two variables for adding up the monthly results, increment these after you calculate the monthly value, and whenever k hits 12, print them and reset to zero. print a final time once you leave the loop. "
int year = loanDurationYears-14; int[] years= new int[loanDurationYears]; periods = loanDurationYears*12; for(int i=0;i<1;i++) { for(year = 0;year<loanDurationYears;year++) { years[year] = year+1;
Code below. I am not sure if my logic is correct. I want to prompt a user to enter registration numbers from 100 to 1000, store the numbers in an array then sort them.
import java.util.Scanner; class regnumber { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("registration number ", 100,1000);
I am writing a program that creates an array with random numbers. Then the user can choose what number of the array he/she wants to check the occurance of. This works fine, but the numbers generated seems very weird, only 2 of the 10 possible numbers are generated. 0 and one of the other 9 numbers, the 0 is always 10100 and the other one is always 101.
import java.util.Random; import java.util.Scanner; public class OppgaveC { public static void sjekk() { int randomArray[]=new int[101]; int countArray[]=new int[10]; Random rand = new Random();
[Code] ....
it also says i have a memory leak on my scanner, ow can i close this?
The program below is intended to find the arithmetic mean of the numbers stored in the array q in two ways: once by storing the numbers in an ArrayList d, where you allow all the necessary conversions to be performed automatically; and once by storing them in an ArrayList e, where you perform all the conversions by hand. Complete the program.
Here is what I have so far:
double[] q = { 0.5, 2.4, 7.4, 2.8, -6.2 }; ArrayList<Double> d = new ArrayList<Double>(); ArrayList<Double> e = new ArrayList<Double>(); for ( double x : q ) { d.add( x ); e.add ( new Double ( x ) );
[Code] .....
Why does it still show "a / d.size?" I thought I fixed that. Whatever, it's supposed to be "dTotal / d.size()", etc.
I am writing a Bingo program for a class and have reached a roadblock. How do I call 5 numbers from the array and where do I store them so I can populate them back into my JLabels on the Bingo card. I'm sure there are more complicated ways to do this, but I'd like to keep it simple so I actually understand the process. I understand that I will need to shuffle the numbers in the array before choosing them, but I also am not sure how to do that.
int [] BArray = {1,2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; for (int index = 0; index > 5; index++) { }
Write the following method that shuffles an array list of numbers.
public static void shuffle(ArrayList<Number> list) package shuffleArrayList; import java.util.ArrayList; import java.util.Arrays; public class ShuffleArrayList { public static void main(String[] args)
This particular program is supposed to prompt the user to input either an uppercase or lowercase Y to process a phone number, they are then prompted to enter the character representation of a phone number (like CALL HOME would be 225-5466), this repeats until the user enters something other than the letter Y. All of the words entered are to be stored into a single array. The program is then to convert these words in the array to actual phone numbers. Here is what I have so far.
import java.util.*; public class Program1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String begin; int phoneNumber = number.convertNum();
[Code] ....
I realize that the second method doesn't have anything to return yet, I just wanted to put that in there while I was doing things that I actually know how to do ha. The convertNum() method is supposed to be the method with which the array of characters is converted to phone numbers.
I'm still trying to think my way through this. I would think it'd be easier to store the inputs from the user as individual letters rather than words for the sake of converting to phone numbers.
Also, we are only supposed to recognize the first 7 letters of each word that is entered, like the CALL HOME example, there are 8 letters but it's still a seven digit phone number, so I'm not sure how that would work.
Also, when printing the phone numbers after they've been converted, we're supposed to print the hyphen after the third number, I have no clue how that would be done from an array.
How to convert numbers into string without using an array and a method ....
Example of arrayed code:
The code here is working but i want to use the other way for not using array just like switches and if and loops only. I made a code here but i did'nt run what i want to output .....
package UnderPackage; import java.util.Scanner; public class NumberToWords { static Scanner input = new Scanner(System.in); public static void main(String[] args) { int number; int b;
public class ReverseOrder { public static Scanner input = new Scanner(System.in); public static void main(String[] args){ int[] numbers; double[] reverse;
how to translate it into Java language due to lack of experience (2 weeks). My solution I've formed in my head is: create a new array for the numbers that are in improvement and then declare a "max" variable. Check which array's length is higher and print that length. What I don't know to do is: I don't know how to create a new array for each numbers that are passing through the condition.
Note: I couldn't find anything on internet about my problem so that's why I'm here.
My code is this one:
class MyClass { static int progresie=0; public static void longest_improvement(Integer[] grades) { for(int i=0;i<grades.length-1;i++){ if(grades[i]<=grades[i+1]){ progresie ++; } } System.out.println(progresie); } }