Unable To Concatenate Two Arrays
Dec 15, 2014
I am trying to concatenate two arrays but on on compiling it is showing
Java Code: import static java.util.Arrays.*;
class Mergesort
{
public static void main(String...s)
{
Mergesort r=new Mergesort();
int x[]={1,2,3,4,5,6};
int y[]={9,8,7,15,14,13,12,11};
[Code]...
View Replies
ADVERTISEMENT
Dec 6, 2014
I am trying to create a program for class the uses two dimensional arrays. I am stuck on the second step that states Use two parallel arrays. One is a two-dimensional array -- a row of this array will hold six values in this order: [0] number of hours worked, [1] hourly pay rate, [2] gross pay, [3] net pay, [4] federal withholding, and [5] state withholding.
This is what I have so far:
Java Code:
double [][] data = new double [30][6];
String [] names = new String [30];
String str = null;
String detail = null;
int n = input(data, names, inputFile); mh_sh_highlight_all('java');
(there's more but i don't believe it pertains to this question)
My question is how would I create this array. Or, is that right above? I've searched online and in my book and I just don't understand.
View Replies
View Related
May 27, 2015
Write a program that declares and concatenates various strings. Declare strings for your first name, middle initial and last name, along with one for your address, city, state and zip. Make an additional string called firstLine, which will be a concatenation of first name, space, middle initial, period, space, and last name. Assign each of these strings a value, and then print the information in the following format:
First Line (First name Middle initial (period) Last name)
Address
City, State
Zip
For example:
John Q. Public
1234 Any Street
Cleveland, Ohio
44101
Now reassign the strings in the same program (Do not create a separately compiled program!) and repeat the printout for different information. When you are finished, your program will print out two groups as above.
The information should be placed into the seven separate strings, then a first line should be formed by concatenating first name, space, middle initial, period, space, and last name. The city and state line should be formed by printing city followed by a comma, a space, then the state (NOT by concatenation). This is so you can see different ways of making lines."
And this is what I have so far:
View Replies
View Related
Oct 1, 2014
class connection {
public static void main (String[] args ) {
String a= "jdbc:oracle:thin:@//erp.oracle.com:1521/orcl" + ","+ "apps" + "," + "apps";
System.out.println(a);
System.out.println(coninfo());
[Code] ....
View Replies
View Related
May 23, 2015
Ok so what I a String array of binary numbers
private String[] encodedNumbers = {"0000", "0001", "0010", "0011","0100", "0101", "0110","0111","1000","1001","1010","1011","1100","1101"};
and what I want to do is simply run through a loop (Which I already made ) that will randomly just put this strings together.
So if the loop runs once it will return something similar to
00001011001101000110
The thing is that I don't want to return such a number as an String, I want it to be returned as a long.This was one of my recent attempts
/* Contains the genes or possible solutions to the problem
*/
public class Genes
{
/* Each element is a binary number that corresponds to index number they have been assigned to, these are the possible genes
* The last 4 elements in the array represent + - * / correspondingly
*/
private String[] encodedNumbers = {"0000", "0001", "0010", "0011","0100", "0101", "0110","0111","1000","1001","1010","1011","1100","1101"};
[code]...
What can I do ? I want them the values returned to be of the long data type, but I don't want the binary numbers to be added together. I just simply want them to be placed one next to each other at random patterns
View Replies
View Related
Mar 7, 2014
<tr:selectOneChoice value="#{bean.aValue}" required="true">
<f:selectItem itemLabel="Option1" itemValue="1"/>
<f:selectItem itemLabel="Option1" itemValue="2"/>
<f:selectItem itemLabel="Option1" itemValue="3"/>
</tr:selectOneChoice>
Supposed that selectItem loads a list from the database.
But I want to display "Option1 - testing" without modifying database value.
testing is a string datatype in the backing bean
View Replies
View Related
Jun 28, 2014
I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff.
View Replies
View Related
Apr 23, 2015
I'm wonder about the issue of constructor for arrays. Let say I have a class tablica, and one component int[] tab. If I get it right until now tab is nothing more than empty reference to some unexisting array?
import java.util.Random;
class tablica{
int[] tab;
tablica (){ // i wish it was constructor
[code]....
Then, I'm trying to build the constructor for class tablica. What can be the parameter of such constructor? Is it fields of array? It is simple forf for basic variable
- I liken values defined in constructor with those global defined in class. But how to do it with array component tab.
If I create array object in main method then how can I use this constructor?
View Replies
View Related
Sep 19, 2014
How do i increase the size of a 2D array from 2X2 to 4X4 where only the boundary elements are zeroes and the rest of them remain the same?
View Replies
View Related
Jan 28, 2015
In the program below I populated three arrays: student id, name, and GPA. The findStudent() method attempts to match users input with the input stored in the studentID array using an if/ else statement. When I use the if/ else statement the else always executes regardless if the IDs match? I am trying to get JOptionPane.showMessageDialog(null, "Incorrect entry"); to print only if the IDs don't match.
Java Code:
//FILE: StudentIDArray.java
import javax.swing.*; //Used for the JOption dialog boxes
import java.util.*; //Used for Scanner input
public class StudentIDArray {
boolean nameFound = true;
final int numOfElements = 2; //Final int to control to loop for data
[code]....
View Replies
View Related
Aug 22, 2014
I'm working on a side project, which will eventually hopefully be a Pokedex, and I've just been going to it at the end of every chapter and using the stuff I've learned to work on it.So I just read chapter 3, which is all about variables and teaches how to use arrays.
my question is, does an array have to be declared inside a method? Because I'm trying to create an array inside a class without any methods and without the main, and I continuously get errors. Here's a quick working of my code that won't compile.
class blah {
blah a[] = new blah[7];
a[0] = new blah();
}
The error message focuses on a[0] = new blah(); Telling me the 0 should be a ], the = is an illegal start of type, so on and so forth. The program compiles completely fine if it's within a method, like this:
class blah {
void a() {
blah a[] = new blah[7];
a[0] = new blah();
}
}
Or if I have public static void main (String[]args); But I'm trying to practice working outside of main.So does an array have to be within a method,
View Replies
View Related
Nov 22, 2014
I have created a class and a matrix of doubles (or at least, I think I have, that's partly what I want to verify).I need to return the values of the array,Here is my class:
public class example{
double[][] Position=new double[2][11];
double calculate(){
for (int time=0;time<=10;time=time+1){
Position[1][time]=time;
Position[2][time]=time+1;
double A=Position[2][time];
return A;
}
}
}
I am getting the error: "This method must return a result of type double", though to me it looks like I am returning double (A).
View Replies
View Related
Mar 15, 2015
I am having trouble conceptualizing how to fill arrays. I understand that I can declare one and number it's elements, and it stores values of a certain data types. I don't really understand beyond that. Like how I would fill and use data in it.
I can be more specific with an assignment I have for school, but need to get started understanding how to fill arrays with data and then how to use that data.
View Replies
View Related
Sep 21, 2014
So im making this ghost game where i display an 8x8 filled with 0s and a randomly generator five 1s in there I can get it to display 0s and add 1s, however sometimes the 1s that are randomly generated sometimes go on the same spot making it look like there are only four 1s. How would i go about fixing that?
package Grade12;
import java.util.Random;
public class Ghost {
public static void main(String[] args) {
Random generator = new Random();
int gameboard [][] = new int [8][8];
int randomx, randomy, counter = 0, sum = 0;
for(int row = 0; row < 8; row++){
for(int col = 0; col < 8; col++){
(gameboard[row][col]) = 0;
}
[code]...
View Replies
View Related
Mar 4, 2014
The assignment goes like this...Write a Payroll class that uses the following arrays as fields:
employeeID - An array of seven integers to hold employee identification numbers. The array should be initialized with the following numbers:
5658845452012578951228777541
845127713028507580489
hours - An array of seven integers to hold the number of hours worked by each employee.payRate - An array of seven doubles to hold each employee's hourly pay rate.wages - An array of seven doubles to hold each employee's gross wages.The class should relate the data in each array through the subscripts.
For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeID array. That same employee's pay rate should be stored in element 0 of the payRate array. In addition to the appropriate accessor and mutator methods, the class should have a method that accepts an employee's identification number as an argument and returns the gross pay for that employee.Demonstrate the class in a complete program that displays each employee number and asks the user to enter that employee's hours and pay rate. It should then display each employee's identification number and gross wages.Input Validation: Do not accept negative values for hours or numbers less than 6.0 for a pay rate.
My problem with this program is that everytime I try to print the employee ID's or the wages, I get hashcode or something like it (#[I1a77cdc or something like that). I tried using the toString method, but it lists all of the values, when I'm trying to display one at a time. Here is the code for the class:
// moduleArray class
public class moduleArray {
final int NUM_EMPLOYEES = 7;
int[] employeeID = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489};
int[] hours = new int[NUM_EMPLOYEES];
[code]...
This is the demo program to list the ID's. I've been messing with it for some time, and right now I just want it to display values.
import java.util.Scanner;
public class moduleArrayDemo {
public static void main(String[] args) {
final int NUM_EMPLOYEES = 7;
int[] ID = new int[NUM_EMPLOYEES];
[code]...
View Replies
View Related
Dec 14, 2014
Okay, so the assignment was creating a word search for the given array. I've created all the code necessary, but I've ran into trouble. This problem occurs with the Up-Forward, Up-Backward, Down-Forward, and Down-Backward sections. If I only set one of these to run, it works. But if I have all 4 set at the same time, it errors out on the first one that runs.
public class P_WordSearch {
public static void main(String[] args) {
char[][] puzzle = {
{'B','O','O','G','S','R','O','W','I','N','G'},
{'E','B','L','G','N','I','M','M','I','W','S'},
{'L','C','E','A','T','I','P','U','P','I','S'},
{'C','M','I','N','C','A','X','Y','O','S','N'},
[Code] ....
View Replies
View Related
Jan 4, 2015
I am receiving one error when using arrays and methods. It's at the bottom of the code and I have commented what the error is .
import java.io.*;
import javax.swing.*;
public class CEO_PROGRAM_PartB
{
public static void main (String[] args) throws IOException
[code]....
View Replies
View Related
Dec 5, 2014
The assignment was to create 3 parallel arrays to make a student database.The first array will contain 4 digit student id's, the second a string array with student names, and the third array is student gpa's. The user is to receive a dialog box asking to enter the student id, and if the id is correct the user is to see the student name and grade. If the user input does not match any value in the student id array, the user is to receive a message stating invalid id. Here is the code I have so far.
For some reason no matter what the user enters, the information for the last array entry is displayed.
public class parallelStudent
{
public static int sequentialSearch(int[] array, int value)
{
int index; //loop control variable
int element; //element the value is found at
boolean found; //flag indicating search results
[code]...
View Replies
View Related
Nov 24, 2014
We had to use these methods with the given parameters and code them correctly. We cannot use any built in java methods for sets.
import java.util.Scanner;
public class setPractice {
public static Scanner kbd;
public static final int MAXSIZE = 20;
public static void main(String[] args) {
kbd = new Scanner(System.in);
int[] setA = new int[MAXSIZE];
int[] setB = new int[MAXSIZE];
int[] intersect = new int[MAXSIZE];
[Code] ....
This is the input given to the program:
How many numbers will be in the 1st set: 3 Enter list of integers for 1st set: 12 3 2
The ascending order for 1st is: 2 3 12
How many numbers will be in the 2nd set: 4
Enter list of integers for 2nd set: 2 3 6 1
The ascending order for the 2nd set is: 1 2 3 6
The intersection of the two sets is: 0 0 0 //Program not correctly print intersection of two sets
The difference of A-B is: //Program is not printing the difference either...
View Replies
View Related
Apr 13, 2014
I am having trouble grasping 2 dimensional arrays .I have a certain problem:
String[][] words = {
{"Red", "Blue", "Green"},
{"Orange", "Purple". "Yellow"}
[code]....
I ran the code and got OrangePurpleYellowRedBlueGreen.
View Replies
View Related
Sep 13, 2014
import java.util.*;
public class OneDimenArray {
public static void main(String[] args) {
double[] decimals = new double[12];
double nums = 0.0;
double a = 1.0;
[Code] ....
These are the erroe codes I'm getting;
OneDimenArray.java:13: error: ']' expected
double[] decimals = double[Scanner.nextDouble()];
^
OneDimenArray.java:13: error: ';' expected
double[] decimals = double[Scanner.nextDouble()];
^
2 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
View Replies
View Related
Sep 15, 2014
I need to send a byte array across a network. I know how to do this. (server->client)
byte[] myArray = new byte[]{0,1,2,3,4,5,6,7,8,9};
DataOutputStream.write(myArray);
... and I know how to receive it.
byte[] myArray = new byte[10];
DataInputStream.read(myArray);
When I send over one of these arrays, it ends up stopping storing values in the array when only about half the array is received, even though the array is sent from the server all at once. This results in the receiver's array, in this case, being something like {1,2,3,4,0,0,0,0,0,0}.
I can easily solve this - and already have - by simply adding a loop onto it and waiting for the bytes to all be received, as the method returns the amount of bytes actually read.
byte[] myArray = new byte[10];
int bytesRead = 0;
while( bytesRead < myArray.length) {
bytesRead += DataInputStream.read( myArray, bytesRead, myArray.length - bytesRead );
}
I am simply wondering if there is a better solution to this, as the current solution isn't that elegant. Did I do something wrong to cause only a part of the array to be sent first? Would it be better to use DataInputStream.readByte() to read off the bytes one by one rather than an array at once, and then store them in an array afterward? Would this cause a performance decrease as each byte is read individually? (I'm sending an array of several million bytes)
View Replies
View Related
Apr 22, 2015
I am writing a code based on the following question: "Write a method called arrayMin that accepts as an argument an array of numbers and returns the minimum value of the numbers in that array.Create an array to test your code with and call the method from main to print the min to the screen".
I cannot seem to get the code to calculate the minimum number.
Here is my progress thus far:
import java.util.*;
public class Lab11q3
{
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
int number;
[code]....
View Replies
View Related
Jun 30, 2014
I am making a 2d game engine and i was wonder is it better to use BufferedImages and subImages to store/render sprites from sprite sheets or use BufferedImages and store it in a pixel array and then manipulate the pixel array to do what you want.
Basically is loading in BufferedImage and getting the tile of the sprite sheet with subImages better than loading in a BufferedImage and then putting the data in a pixel array and making a new array with the part of the BufferedImage you want.what i have been told the BufferedImage and subImage use more of the graphics card and the pixel array method uses more of the processor.
View Replies
View Related
Mar 26, 2015
how to loop my arrays, so when I sort them (highest/lowest) the 2nd array corresponds to the sorted array
import java.util.Scanner;
import java.util.Arrays;
public class ArraysArrays {
public static void main (String[] args){
[code]....
View Replies
View Related
Sep 18, 2014
For basic arrays, we can directly combine declaration and initialization as E.g: int[] num= new int[2]
But can we do this do for forming class object arrays? like
class stu
{
.....
}
stu[] s=new stu[2]
????
View Replies
View Related