hi there, so i have this array that is made of 31 classes (i don't even know if you can do that) and each class has 2 strings and 1 integer, but with each of the 31 classes one of each of those strings i want to have a gap in the middle. so here's an example of one class: private ... |
Hello, i have 2D array and initialise it with nested loop. More specific in place array[11][2] initialise it as element of another class i created. Now if i use system.out to print this place after the end of loop, content is ok, but if i print it in a method i created is null!!! Im not doing anything in that place ... |
Hi All, I have a requirement like, i have to get last ten years in one Array based on current year. import java.util.Calendar; public class DecrementYear { public int[] lastTenYears() { Calendar cal = Calendar.getInstance(); int year = cal.get(cal.YEAR); return null; } public static void main(String args[]) { DecrementYear dy = new DecrementYear(); int arr[]=dy.lastTenYears(); } } I am calling lastTenYears() ... |
Hello, I have an integer array size of ten. Im trying to create a method that each time, will store in array the ten recent calculations. For example if i do 40 calculations in array i want to each time storing the 10 most recent. How i can achieve this? thank you |
|
Thanks, I read! See my code: public class arrayTest { //inicializao do programa public static void main(String args[]) { int[] anArray; //declares an array of intengers anArray = new int[10]; anArray[0] = 100; //initialize first element anArray[1] = 200; //initialize second element anArray[2] = 300; anArray[3] = 400; anArray[4] = 500; anArray[5] = 600; anArray[6] = 700; anArray[7] = 800; anArray[8] ... |
|
|
Hello all! Not can understand ARRAY with FOR. See: I use the FOR for show element of ARRAY in a single line. So, see code: Code: public class arrayTest { //inicializao do programa public static void main(String args[]) { int[] anArray; //declares an array of intengers anArray = new int[10]; anArray[0] = 100; //initialize first element anArray[1] = 200; //initialize second ... |
|
Hi! import java.util.Random; public class matches { public static void main(String args[]){ String names[] = {"A","B","C","D","E","F","G","H","I","J"}; int numb; int numb2; Random randInt = new Random(); for (int i=0; i < 5; i++){ numb = randInt.nextInt(10); numb2 = randInt.nextInt(10); //Just in case same fighters. if (numb == numb2){ numb2 = randInt.nextInt(10); } System.out.println(names[numb] + " vs " + names[numb2]); } } } ... |
|
I am new at Java and I am not sure if I am posting at the right place. Please let me know if I am not. I am trying to transfer a 2 dimension array to a text file but get the following runtime error: java.lang.ArrayIndexOutOfBoundsException: 2 at Parts.writeArray(Parts.java:25) at Parts.main(Parts.java:13) Here is the code I have so far: import java.util.Scanner; ... |
|
I have several questions as follows and will appreciate any one can help. 1. I need to read data from text file and strore them in an array. It is a name game from SSA. Here is the text file. I need to read them and then store in an array. The number is the ranking of the name in the ... |
Hi I have an array which stores info about 20 teams. I created another array which stores the exact info of the first array but the teams are shuffled. I also have a third array this time of 10 which is being used to store matches i.e. 10 matches between the 20 teams. Now for the matches, I have a class ... |
I'm somewhat familiar with multidimensional arrays in BASIC varieties, but not quite understanding the arrays of arrays. In an array of arrays of integers it seems that everything up to but excluding the last index points to a reference variable. So in the case of int myArray [] [] [] [] = new int [5] [4] [3] [2] (pretend I filled ... |
|
|
Hi all. I'm building a version of battleships, two arrays are created, x and y, when added to the array list Ships. When i run the program i get the same variables appearing in each instance of the array. Any ideas? import java.util.*; public class Ship { ArrayList Ships = new ArrayList(); int[] x = {0, 0, 0, 0}; int[] y ... |
You want a new byte array large enough to hold all the values from 0 to 0xffffffff inclusive. You are using this as a bitmap, where each value uses 1 bit. Instead of writing false-true-false-true-false-true-false-true, you can write 01010101 and be sure to squeeze those 8 boolean values into 8 bits (1 byte). So to fit all the values from 0 ... |
|
Hi all. I have to write a java program that allows a user to enter an octal digit and output the binary equivalent for as many numbers as the person wishes using a direct access method. The error is that even though it compiles, it loops the binary equivalent. The code goes as follows: import java.util.Scanner; // initialize scanner class for ... |
|
I am having trouble understanding how this works? class TGFace { // Fields: Vector indices; // Constructors: public TGFace() { this.indices = new Vector(); } // Methods: // Add an index to a vertice list to the face. public void addIndice(int i) { this.indices.addElement(new Integer(i)); } } then later on in the program it adds this: types[0] = new TGObject(); types[0].addVertice(new ... |
Hi im at my wits end here trying to get this simple array problem sorted and would appreciate some help. I have 2 arrays, one for 'candidates' filled with names. and the other is 'votes' which is filled via scanner. Simple voting. the output is the name of the candidate with the total amount of votes they got. I have the ... |
|
I have 3 arrays that were filled from a file. The first column is breakfast, the second column is lunch, and the third column is dinner. But now I have to get the totals for each day (or row), and I don't know how to do that without having a multi dimensional array since I already have 3 arrays filled. The ... |
|
|
If i call getClass method on an array reference variable, for instance short[]x=new short[2] i get this class [S if its an int array i get class [I if its an object array, assume the class name is A, i get class [LA 1.What is this really?. Which class do arrays really belong. And i asked another question related to this ... |
public class Tester { public static void main (String args[]) { int x[], y; x[] = new int[] {1, 5}; y = 5; } } This doesn't compile. The problem is fixed if I just declare and initialize x[] on the same line, but I'm curious as to why it doesn't compile. My book says it should. It also compiles if ... |
Hello, Im working on the magic squares assignment and the tester asks the user to input values on a single line to be used for the magic square class. My problem is how do I take values given on one line and seperate them into an array or 2D array? This is an example user input: Enter a sequence of integers, ... |
I am writing this very simple program, but for some reason I get a "ArrayOutOfBoundsException" import java.io.*; class devshed { public static void main(String[] args)throws IOException { BufferedReader in = new BufferedReader (new InputStreamReader(System.in)); System.out.println("Type \"help\" to get Started" + "\n"); String state = "Enter"; while (state != "Exit") { System.out.print("> "); String userInput = in.readLine(); String[] command = userInput.split(" "); ... |
package com.rxBatch; import java.io.File; public class Test { public static void main(String[] args) { String[] filesFromDest = new String[500]; String[] source = {"C://filesys/fileSys1"}; File f1 = new File(source[0]); fetchFilesFromDirectory(f1, filesFromDest); for (int i = 0; i < filesFromDest.length; i++) { System.out.println(); } } public static void fetchFilesFromDirectory(File f, String[] listOfFiles) { File[] fileSys2 = f.listFiles(); for (int i = 0; i ... |
not sure if I am going about it the right way but this is what I am trying to do and what I have so far. I want the program to randomly pick something from the terminology array and ask a question for the user to answer. So far I can get it to do that and have the user input ... |
import java.util.*; import java.lang.*; import org.annolab.tt4j.*; import static org.annolab.tt4j.Util.join; public class tagging { public static void main(String[] args) { System.setProperty("treetagger.home", "c://treetagger"); TreeTaggerWrapper tt = new TreeTaggerWrapper(); try { tt.setModel("/c:/treetagger/models/english.par:iso8859-1"); tt.setHandler(new TokenHandler() { public void token(String token, String pos, String lemma) { System.out.println(token+"\t"+pos+"\t"+lemma); } }); tt.process(asList(new String[] {"This", "is", "a", "test", "."})); } finally { tt.destroy(); } } } sir above is ... |
int numOfPeople = (fields.length - 6) / 4; for (int i = 1; i == numOfPeople ;i++){ String name = fields[6 + 0] ; int height = Integer.parseInt(fields[6 + 1]); double weight = Double.parseDouble(fields[6 + 2]); int age = Integer.parseInt(fields[6 + 3]); //test System.out.println( name + " " + height + " " + weight + " " + age ); ... |
Yes, there is. It is quite easy. Start by writing a method which swaps two elements in an array, like this/** * Swaps the i-th and j-th elements in an int array. * Has no effect if i and j are the same. *@param array An array whose two elements are to be swapped. *@param i the index of one of ... |
Hi, I'm trying to print a 2-d array of powers, but I'm having trouble getting my head around the idea of columns and rows. So if I'm correct, is my inner loop assigning values in the array for columns, and my outer for loop is for the rows? Or should I have a separate array for each row of the table? ... |
|
I have an assignment due on Tuesday and I'm having a few problems with arrays. First I can't seem to get my array to display vertically, it just comes out like 12,34,67,etc. also I'm having difficulty getting the highest and lowest number from the array. My program is supposed to get temperatures from the user and calculate the average, sum, high ... |
Code: import java.io.*; import java.util.*; class Comp2004{ static int[]results; public static void main(String[] args){ //write a method which returns the largest sum of any consecutive integers in the array int []num = {27,6,-50,21,3,14,16,-8,42,33,-21,9}; int []results = new int[100]; int val = LargestSum(num,results); System.out.println("The largest value is :"+ val); }//main public static int LargestSum(int[]num,int[]results){ int x = 2;//start for loop to run ... |
hi all, my project is in pending because of the one major task ..i connected two different databases and exported the values using separate excel sheet for each databse.Now i need to add both the tables from excel and output the value in third excelsheet. For ex , Table 1 service name failedcount totalcount partyadd 10 200 partysub 20 100 partydiv ... |
Re: Java Code Array ( Array to be viewed ) here is my code....I need the users to see the output values in an Array the javac compile works ,....the java does run in dos....it is just I need the output to be an array Code: import java.text.*; //20 May 2008, Revision ...many import java.io.IOException; class mortgage //program class name { ... |
|
|
Hi. In your code, you send two parameters to the num method, a[] and i. I am going to assume that i is the number that needs to be tested for. So... In your code, make sure you check every number in the array by using j as the index for the array. Also, you should not create a again inside ... |
I'm trying to create a calendar program in Java. I am hoping to display an array of input fields for the user with each field corresponding to a given date. I want to allow the user to input appointments as strings. Since it is expected that some dates will contain no appointments (i.e. the array entry contains a null object) and ... |
hi everyone .. i wanna store random numbers in an array then ask the user to guess it .. and compaire with the random array well am stuck at the array part . cant get it to work at all .. can anyone help pls .. just tell me how to store a randoms in array with for loop .. then ... |
I am working on a project that takes the user input for 10 midTerm1, 10 midTerm2, 10 final exam grades, Then the program is suppose to add the 3 to find a min and max then display the min and max. I can't figure out how to get the 3 arrays into the final array and add them. Code: import java.util.Scanner; ... |
the program below is suppose to give you a choice of adding, sum, and exit. the use can choose 1 to add another number until the array memory runs out (4 inputs will be used in this case). if and when the user chooses 2 then the numbers inputted by the user would be added and then printed out. 0 is ... |
hello guyz, can anybody help me about this problem: "Create a java program, that will compute the union, intersection, and difference of a given sets... These given sets must be coming from a user. Example, they want 3 sets or 4 or 5 sets (it must be at least 2 sets) and these set will be named as set 1, set ... |
|
I need to write a java program that will read data from a file. The data is: John Doe 75 Joe Blow 65 Mary Smith 80 John Green 82 Jill White 97 The program is suppose to read into three separate arrays: firstname array, lastname array, and a score array. The output should be the initials followed by the score in ... |
A date structure has a day/month format. A day ranges from 1 to 30 and a month is one of the months of the year. Specify an array of integers called day to hold the values of day, and an array of String called month to hold the possible values for a month e.g. January, February, etc. Assume all months have ... |
|
|
|
I am kinda teaching myself java and got stuck trying to create a a program to translate 10 words bi-directional from english to spaniah, using two different String Arrays one consist of english words and one consist of spanish words. Can someone help this novice out? import java.io.*;//tell Java we are using java.io libary. import java.util.*;//Java utility package also for Scanner ... |
class Test{ public static void main(String[] args){ int x=0; int [] num = {1,1,3,3,3,3}; int [] a = new int [4]; for(int i = 0; i < num.length-1; i++){ x =++num[i]; a[i++] = x; System.out.println("num :"+ i+" " + x); } for (int j = 0; j< a.length; j++){ System.out.println(a[j]); } }//end main }//end class |
Hi. My instructor gave us an assignment to calculate the modes in an array. Basically, the array values (not the index) contains the frequencies of the index number (like a histogram). For example, since the value of "10" (the highest number for values) occurs in index numbers 2, 4, and 11, the program must output that the "mode occurs at index ... |
62. array java-forums.org |
I am trying to write a code with parallel arrays. I'm not sure where I'm going wrong. Please help. THIS IS WHAT I'M TRYING TO DO: I am trying to create an application for a family who pays allowance to their children based on age, and if he/she has a job. The application will first ask for names and ages. Then ... |
Here is my problem: I am working on a project which is writen by JAVA. In JAVA, I have a 3D volume called velocity_java: float [][][] velocity = new float [NY][NX][NZ]. I need to use JAVA Interface to connect with my C program. In my C program, I define velocity as 3D array velocity_c float ***velocity; /*pointer*/ velocity = alloc3float(NY,NX,NZ). /*allocate ... |
I have an assignment due on tuesday and i'm having a few problems with arrays. First I can't seem to get my array to display vertically, it just comes out like 12,34,67,ect. also I'm having difficulty getting the highest and lowest number from the array. My program is supposed to get temperatures from the user and calculate the average, sum, high ... |
Hi, I'm desparately trying to know how to do the code whereby I can dispaly the wrong questions answered from category chosen. There are 4 categories with 5 questions each and I need to dispaly all the wrong questions. So far my code only show the question 1 all the time.:confused: Java Code: import javax.swing.*; public class Quiz {//Quiz Class public ... |
67. Arrays java-forums.org |
Hello Guys, i have a little logic problem in my program. The program is easy, has no real use and is for my learning only. I try to implement a divideandconquer searchalgorithm inside an array. For this purpose i am using a method who uses two parameters, a stringarray and the searchedname. The problem: If the searchedString is not the median ... |
Is this an array or array list? Say its an array. String[] someArray = {"dog", "cat"}; in order to access objects knowing their index you can just say String animal = someArray[0]; Knowing this, you should be able to figure out how to do so knowing the value and not the index. |
70. Arrays java-forums.orgHello, me again with yet another issue with Java syntax! I am about to give up with Java because I am really having an issue with grasping the syntax, but I'm not defeated yet! Basically this is what I need to do: Write a program that prompts a user for a list of 5 prices. The program is then to compute ... |
why oh why doesn't this array work.. :( i am able to write things into txt file but i cant seem to delete the null value for the array.. can someone please help.. the problem should display the whole content first, which is [1, , ,2] than it should display the content without the null which is [1,2] Java Code: class ... |
I am trying to figure out ow to read integers from a user specified file in to an array. Since i don't ave any information about te file except for the fact that it is more or less a matrix, how do I get the program to read those numbers into a multidimensional array ? |
This is what I ave so far, but it is spitting out random yes's and no's. import java.util.*; import java.io.*; import static java.lang.System.out; public class Squares { public static void main(String[]args) { int square; int matrix [][]= new int [64][64]; int counter=1; int n; Scanner filename = new Scanner(System.in); out.print("Enter file name: "); String inputfilename = filename.nextLine(); out.print("Enter output name: "); ... |
Hi, I have naerly 80,000 records in my database. When user clicks on search it fetches the corresponding data in an array from database. When it tries display the records on page it becomes really very slow. I just display 20 records per page. I want that when it gets data from database, it should get the first 20 records and ... |
hello I have a problem with a question...If anyone knows help me please... Create 3 class 1.StringBuffer(SB) 2.One dimensional array with chars.. 3.Construstors def. expl. show your information which comes from array and send it StringBuffer sb like these...it was more than this but remembered basic. this is a one program as you know...I didnt do that if someone can ... |
|
Good Morning I can't wrap my head around methods and arrays in java. Please help with the following: [*]create a method called addCustomer(). the method must request the user to enter info for a customer and add the customer to the customer list.[*]First an array called customer list must be used throughout the class to store info about a Customer and ... |
78. Arrays java-forums.orgimport java.io.*; public class Simulate { private static int noOfVehicles = 5; private static Vehicle vehicles[]; public static void main(String[] args) { /*int [] VehicleId = new int[5]; VehicleId[0] = 1; VehicleId[1] = 2; VehicleId[2] = 3; VehicleId[3] = 4; VehicleId[4] = 5; */ // Vehicle vehicles[] = new Vehicle(); Thread t1 = new vehicleId(VehicleId); Thread t2 = new vehicleId(VehicleId); Thread ... |
Hey guys, Hopefully here I can find some "simple" help for someone fairly new to java like me. Other forums people were helpful its just that I still find it hard to understand some of the concepts they are giving me. I'm working on a program with 9 classes, I've filled most of the object classes according to what I've been ... |
Hello Again, Yet another road block in my destination to completing my program. I wanted to create a MultiColumn Combobox and needed to store my Database values into an array so I get get them into the Combobox. I'm having trouble getting this code to work properly. It seems that the the combobox wont accept the variable items maybe because it ... |
actually i've tried that too. p.lenghth... i think it might be something simple but not getting at this point...i guess goto barns and nobels to see/read book lol public static void main(String[] args) { int even=0, odd=0; int p[]=new int[25]; for (int i=0;i |
|
Hi, I'm new to Java and was wondering if anyone could help me with these two array problems. 1: I have made this code that works to create multiplication tables with for loops: Java Code: public class MultiplyTables { public MultiplyTables() { } public void printTable(int x, int y) { int [][] grid = null; grid = new int [x+1][y+1]; for ... |
Well, this is my first post on Java-Forums.org, so hello! :D I haven't been working with Java for a very long time, but have a good experience with JavaScript/ActionScript, HTML, and PHP. I am working on a console (text) RPG for my first real project, and I am using Scanner for input. It's been working out well, but I've been using ... |
(ii) The Cca class represents a Cca offered by the school. It has the following attributes: a) ccaID (String) : an id that uniquely identifies a Cca b) name (String) : name of the Cca (e.g. Archery) c) numOfVacancy (int) : number of vacancies available in the Cca d) studentList : an array of Student currently involved in the Cca e) ... |
the outer loop will continue to loop until i is no longer less than rows and the inner will keep looping until j is no longer less than columns. In the loop, when you find an empty seat (the array holds the number 0), you are setting the seat occupied by setting it to 1, and then setting your i and ... |
Java Code: import java.util.Random; public class Random100 { /*This is a program to generate random numbers between 1 and 999 with no repetitions in the sequence */ public static void main(String[] args) { Random rand = new Random(); for (int count = 0; count < 10; count++) //allocates the rows of 10 x 10 random numbers { System.out.println(); for (int i ... |
I have a program that i have to convert to using arrays instead of what i have to do the same thing and i'm not the strongest with array can any one help? ... i had hoped to just attach this but it is too big so unfortunutly i have to just post it import java.io.*; import java.util.*; import java.text.*; public ... |
I'm writing a method to take an integer from the user and swap each pair of digits starting from the least significant. E.g., if the method is called with 232563 it would return 325236, or 1804982 returns 1089428. In the second case, the most significant digit, the "1", has no digit to swap with so remains in the same position. So ... |
Hello, I'm a bit confused on how to do this. I'm supposed to open a dictionary file and store all of its values into an array. My guide tells me that I need to: "read in the name of the dictionary file from command-line-arguments, then read in a dictionary of words from the data file, store each word in an array....." ... |
91. Arrays java-forums.orgI am working on a program that asks the user to input students names, their address, education level, GPA, etc. But I need to use an array so the names of the students are stored so they can be printed when the user exits the program. My code only prints the name of the last student entered. I tried using an ... |
hi guys. i need help understanding how to use these together. i have to write a program that finds the average of a set of numbers (from an array), but use 2 methods, one returning an int, and the other a double. i have just about everything, i just don't know how to call and display the 2 values..? |
I have a program for a real estate company that displays a menu from which the user selects and can search unsold listings, change prices, etc... Everything is working except for making a sale, and updating selling price I assume problems are related. Java Code: public class PropertyListing { int listingNumber; char listingType; String location; String description; float askingPrice; float sellingPrice; ... |
you can use a 2 dimensional array and use two for loops to set the values. int[] massiveArray = new int[] {1,2,3,4,5,6,7,8,9 ... 328,329,330}; int[][] smallerArray = new int[30][10]; for (int i=0; i<30; i++) { for (int j=0; j<10) { smallerArray[i][j] = massiveArray[i*10+j]; } } Something like that will work I think. |
|
96. Array java-forums.orgGood point -- I used arraylist in my example because I did not want to confuse the point with keeping track of an index, max size, etc... I do however recommend using ArrayList since it is a dynamic array. Since this is an app that takes user input, it is likely that the number of inputs is unknown or variable. If ... |
public static void getMostCommonNumbers() { int count = 6; int [] high = new int[count]; for (int i = 0; i < count; ++i) { high[i] = -1; } for (int i = 0; i < numFreq.length; ++i) { for (int j = 0; j < count; ++j) { if (high[j] != -1 && numFreq[i] > numFreq[high[j]]) { for (int k ... |
|
Hi everyone, For the purposes of my program i need to make an array out of properties object. Can you please point me in the right direction here? This is what i put together but it does not work String[] schemas = null; for (int i =0; i < databaseConnectionStrings.keySet().toArray().lengt h; i++) { schemas[i] = databaseConnectionStrings.keySet().toArray()[i].toString(); } Basically i need to ... |
|