Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/articles/java-tutorials/)
-   -   Multi-dimensional arrays in Java (http://www.go4expert.com/articles/multi-dimensional-arrays-java-t1162/)

itzkloive 23Mar2008 19:51

Re: Multi-dimensional arrays in Java
Can some one help a novice

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

public class transWords //Naming the program.

public static void main(String[ ]args)throws Exception
//This set-up allow for user to input using keyboard.
Scanner input= new Scanner(System.in);

//Declaring Array String.
String[]englishTrans={"color","white","blue","green","blac k","purple",};
//Declaring Array String.
String[]spanishTrans={"en color","blanco","azul","verde","negro","purp˙reo", };

pradeep 23Mar2008 22:33

Re: Multi-dimensional arrays in Java
What's the exact nature of help you are looking for? the code snippet is probably incomplete!

shilpa dessai 26Mar2008 18:34

Re: Multi-dimensional arrays in Java
hi Pradeep,
For sorting a 1D array we used the simply Bubble sort aLgorithm which worked perfectly fine...but we cant write the code 4 the 2D array as we had written earlier....

Mazharul 11Aug2008 14:18

Re: Multi-dimensional arrays in Java
i want to show a 2D array corresponding to a .jpg/.gif/.png image file in a separate window. suppose i have...
class Image {
protected int width,height;
// 'samples' stores the image pixel values.
protected int[][] samples;
// Constructor: Reads the image from the
// specified file name.
public Image(String filename)
throws Exception { read(filename); }
// Returns the pixel width of the image.
public int getWidth() { return width; }
// Returns the pixel height of the image.
public int getHeight() { return height; }
// Reads the image from the specified file
// name into the 'samples' array. Throws an
// exception if the image is stored in an
// unsupported file format (currently only
// .GIF, .JPG, and .PNG are supported by Sun).
public void read(String filename)
throws Exception {
// Extract the file name suffix...
from the startup java file like..
import java.awt.*;
import javax.imageio.*;
class TestImage {
public static void main(String args[])
throws Exception {
// Create a frame to display the image.
Frame frame = new Frame("Test Image");
Graphics gc = frame.getGraphics();
try {
// Read the image from the file.
Image img = new Image("Horse.jpg");

I want to access the int [][] samples array then want to disply this array values in a separate windo or applet..How to approach......

majidpucit123 9Sep2008 12:24

Re: Multi-dimensional arrays in Java
i'm trying to create a method that adds an element in an existing string array. Kind of like the arraylist "add()" method.
so far, i have this

String[] addToArray(String[] strArray1, String s)
return strArray1+s;


but this doesnt work...

pradeep 9Sep2008 14:16

Re: Multi-dimensional arrays in Java
There already exists such a method, it's called push!

new2Java 10Dec2008 03:41

Re: Multi-dimensional arrays in Java

I need to compare 2 words in a given name and see if any part of the name in index [0] (first name and/or surname) matches the rest of the names. For instance,

robert smith | robert mathews | john robert | john roberts

Basically, only the first and lastname in the first index ("robert smith") needs to be compared with rest of the first and the last names. '

How do I go about this?

I'm successful in comparing just 1 word. eg: robert|RoBERT|smith
boolean result1= choiceKeys[0].equalsIgnoreCase (choiceKeys[i+1]);

What should I do when I have 2 words?

Thanks in advance,

thusha 13Aug2009 13:20

Re: Multi-dimensional arrays in Java
I am inteested in adding elements to 2D array.
So i do like this
i have always one input as prod id ; where i get from parameter

then the for loop

int n = productsid;
                              for( row=0;row<10;row++) {                     
                    year2007[n][row] = (float) tot;

but when i display my array
i dont get the prod id?? what ican do ??

Theone 17Dec2009 18:30

Re: Multi-dimensional arrays in Java
Hi Pradeep,
Can you use a 2d array to make a chess board and store the pieces within it?.

technica 18Dec2009 09:58

Re: Multi-dimensional arrays in Java
Thanks for posting. A article on handling arrays for sorting and searching would be great.

All times are GMT +5.5. The time now is 15:53.