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.
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.
import java.util.*; public class Program1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String begin; int phoneNumber = number.convertNum(); System.out.println("Please enter an uppercase or lowercase Y when you are ready to enter a telephone number: ");
[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.
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.
I need to receive input from the user, as many times as he wants. tha is done with the while loop. I also need to output the min and the max numbers the user enters, therefore i have the if statememnts. also if the user enters only one value i need to output that one value as the min and the max.
int min =0; int max = 0; int option = JOptionPane.YES_OPTION; while ( option == JOptionPane.YES_OPTION){ String dataString = JOptionPane.showInputDialog("Enter an integer"); int data = Integer.parseInt(dataString);
One of the requirements of my programming assignment is that a user enters a command along with two numbers. For example, if I entered the following command:
I 5 6
The program create an image like this (it wouldn't be outputted though):
00000 00000 00000 00000 00000 00000
It creates a 5 x 6 "image". This is where my troubles begin. The program should also accepts other commands, such as:
L 3 2 F
which would produce (also not outputted):
00000 00F00 00000 00000 00000 00000
Here is my method for creating an "image" with an M * N array
for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++) { System.out.print("0"); } System.out.println(); }
The code works, but I need to store the image in an array so it can be changed by other methods (I can't create the image manually every time). I tried doing something like this but it doesn't work:
public static String[][] createImage(int row, int column) { String[][] image = new String[row][column]; for (int i = 0; i < column; i++) { for (int j = 0; j < row; j++) { image[j][i] = "0"; } System.out.println(); } return image; }
This method outputs as many blank lines as the columns I entered and the memory location of image.
So my question is: how would I store "0" in a 2D array so that it can be accessed and changed by other methods?Or, am I using a 2D array incorrectly and will the image have to be created manually every time? If so, how would I output image if it is created in a separate method?
I am having trouble fixing and figuring out how to change my code. My out put is very off.
" Enter a 3-by-3 matrix row by row: 1 1 1 1 1 1 1 1 1 Sum of the major diagonal is 6.0 Sum of the values of the column are: 10.0 Sum of the values of the column are: 20.0 Sum of the values of the column are: 30.0 "
Code is below:
public static void main(String[] args) { double[][] m = new double[3][3]; m = createArray(); } private static double[][] createArray() {
I need to generate a league table in Java based on results provided in the shape of user input. I have the 6 teams in an array. I need to ask the user how many wins, draws, losses each team has had.
for (String element : teams) { System.out.println( "Please enter the number of wins, draws and losses for " + element); int[] wins = new int [6]; int[] draws = new int [6]; int[] losses = new int [6]; }
How do I pull 3 separate values from the user and then store each value in a separate element of each array? so if one team wins 3, draws 2 and loses 1 - I need to put 3 into the wins array, 2 into the draws array and 1 into the losses array? I then need to total all this in a table.
public class MonthsName { static String monthsName[]; public static void main(String[] args) { String[] months = new String[13]; months[0] = null ;
[Code] .....
I keep getting 1 error that tells me this. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at MonthsName.main(MonthsName.java:22) Java Result: 1
Just before that netbeans couldn't find the main class. I was wondering if it netbeans or my code that's wrong.
My assignment was to create a class and then write a program that uses the methods of the class I created. All the output is correct except for the Question # Missed. It prints [I@1dd0fe7. The wrong question numbers have to be stored into an array and that array printed. I've tried using a for loop to print, rearranging the code, setting the code to how I did in the other methods. I either get this [I@1dd0fe7 -or- a bunch of 0's. I'm not sure if I am calling the method incorrectly, or just do not have the correct set-up to print the array, or if I am just not grabbing the ones that are incorrect.
public class DriverExam { // Fields private boolean result; private int testTotal; private int numWrong; private int [] numMissed; private char [] answerKey;
I am reading records from a txt file and storing it into an array
import java.util.*; import java.io.*; public class PatientExercise { //patients exercise time public static void main (String[]args) throws IOException{ Scanner in = new Scanner(new FileReader("values.txt")); double [] patientTimeRecords = new double [300]; int noExerciseCount=0, numPatients =0; double highest=0, lowest=0, avg=0, totalTime=0;
[Code] ....
However an error msg keeps popping up:
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:907) at java.util.Scanner.next(Scanner.java:1530) at java.util.Scanner.nextDouble(Scanner.java:2456) at pastpapers.PatientExercise.main(PatientExercise.ja va:44)
line 44 is:patientTimeRecords[i]= in.nextDouble();
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 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)
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.