Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 18th, 2007, 10:06 AM
Authorized User
 
Join Date: Nov 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chris1012
Default muti dimensional arrays help:(

ok guys i know am a complete pain but am still having problems am using edit plus to construct this java program. am now focusing on multidimentional arrays and am now trying to construct a 3 dimensional array this this is what i've got so far

but i keep getting this compile error like wtf am i doing wrong i think personally its to do with the index and the initial setup of the array heres the compile error any way.

found: java.lang.String[][]
required: java.lang.String[][][]
                          String names [][][] = new String [21][3];

        String names [][][] = new String [21][3];
        names[0][0][0]="chris";
        names[0][1][0]="Elshaw";
        names[0][1][2]="Maths";

        names[1][0][0]="c";
        names[1][2][0]="c";
        names[1][2][3]="c";

        names[2][0][0]="c";
        names[2][3][0]="c";
        names[2][3][4]="c";

        names[3][0][0]="c";
        names[3][4][0]="c";
        names[3][4][5]="c";

        names[4][0][0]="c";
        names[4][5][0]="c";
        names[4][5][6]="c";

        names[5][0][0]="c";
        names[5][6][0]="c";
        names[5][6][7]="c";

        names[6][0][0]="c";
        names[6][7][0]="c";
        names[6][7]="c";

        names[7][0][0]="c";
        names[7][0]="c";
        names[7][9]="c";

        names[0][0]="c";
        names[9][0]="c";
        names[9][10]="c";

        names[9][0][0]="c";
        names[9][10][0]="c";
        names[9][10][11]="c";

        names[10][0][0]="c";
        names[10][11][0]="c";
        names[10][11][12]="c";

        names[11][0][0]="c";
        names[11][12][0]="c";
        names[11][12][13]="c";

        names[12][0][0]="c";
        names[12][13][0]="c";
        names[12][13][14]="c";

        names[13][0][0]="c";
        names[13][14][0]="c";
        names[13][14][15]="c";

        names[14][0][0]="c";
        names[14][15][0]="c";
        names[14][15][16]="c";

        names[15][0][0]="c";
        names[15][16][0]="c";
        names[15][16][17]="c";

        names[16][0][0]="c";
        names[16][17][0]="c";
        names[16][17][18]="c";

        names[17][0][0]="c";
        names[17][18][0]="c";
        names[17][18][19]="c";

        names[18][0][0]="c";
        names[18][19][0]="c";
        names[18][19][20]="c";

        names[19][0][0]="c";
        names[19][20][0]="c";
        names[19][20][21]="c";

        names[20][0][0]="c";
        names[20][21][0]="c";
        names[20][21][22]="c";

in opposite world i love programming
__________________
in opposite world i love programming
 
Old December 18th, 2007, 11:43 AM
Authorized User
 
Join Date: Dec 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

        String names [][][] = new String [21][3][];
        names[0][0][0]="chris";
        names[0][1][0]="Elshaw";
        names[0][1][2]="Maths";

        names[1][0][0]="c";
        names[1][2][0]="c";
        names[1][2][3]="c";

        names[2][0][0]="c";
        names[2][3][0]="c";
        names[2][3][4]="c";

        names[3][0][0]="c";
        names[3][4][0]="c";
        names[3][4][5]="c";

        names[4][0][0]="c";
        names[4][5][0]="c";
        names[4][5][6]="c";

        names[5][0][0]="c";
        names[5][6][0]="c";
        names[5][6][7]="c";

        names[6][0][0]="c";
        names[6][7][0]="c";
        names[6][7]="c";

        names[7][0][0]="c";
        names[7][0][0]="c";
        names[7][9][9]="c";

        names[0][0]="c";
        names[9][0]="c";
        names[9][10]="c";

        names[9][0][0]="c";
        names[9][10][0]="c";
        names[9][10][11]="c";

        names[10][0][0]="c";
        names[10][11][0]="c";
        names[10][11][12]="c";

        names[11][0][0]="c";
        names[11][12][0]="c";
        names[11][12][13]="c";

        names[12][0][0]="c";
        names[12][13][0]="c";
        names[12][13][14]="c";

        names[13][0][0]="c";
        names[13][14][0]="c";
        names[13][14][15]="c";

        names[14][0][0]="c";
        names[14][15][0]="c";
        names[14][15][16]="c";

        names[15][0][0]="c";
        names[15][16][0]="c";
        names[15][16][17]="c";

        names[16][0][0]="c";
        names[16][17][0]="c";
        names[16][17][18]="c";

        names[17][0][0]="c";
        names[17][18][0]="c";
        names[17][18][19]="c";

        names[18][0][0]="c";
        names[18][19][0]="c";
        names[18][19][20]="c";

        names[19][0][0]="c";
        names[19][20][0]="c";
        names[19][20][21]="c";

        names[20][0][0]="c";
        names[20][21][0]="c";
        names[20][21][22]="c";


check your counting
 
Old December 18th, 2007, 02:41 PM
Authorized User
 
Join Date: Nov 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chris1012
Default

what do u mean by check my counting this is the thing the number sequence confuses me thats the only thing can u help me with that all am looking for is an example like mine but is the number sequence right:S sorry i know am a pain and a complete nube

in opposite world i love programming
 
Old December 18th, 2007, 04:32 PM
Authorized User
 
Join Date: Dec 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default


    String names [][] = new String [3][3];

    names[0][0] = "chris";
    names[0][1] = "Elshaw";
    names[0][2] = "Maths";

    names[1][0] = "a";
    names[1][1] = "b";
    names[1][2] = "c";

    names[2][0] = "1";
    names[2][1] = "2";
    names[2][2] = "3";

    for(int i=0; i<3; i++)
    {
      for(int j=0; j<3; j++)
          System.out.println("names[" + i + "]" + "[" + j + "]" + " = " + names[i][j]);

      System.out.println("----------------------------");
    }


 
Old December 19th, 2007, 08:46 AM
Authorized User
 
Join Date: Nov 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chris1012
Default

hey hombre i appreciate your help on this i was just wondering if i could get your advice on another subject area so far i've got loads of system.out.printlns and 1 2 dimensional array and 1 3 dimensional but the dimensional array is primairily number it includes a decimal point of which is set as a string value. am just wondering can i parse this value with including the decimal point there ino a double parsin isn't to familiar to me i've done it with variables is it pretty much the same way?

my code is shown below all of my values are displayed on the system.out.println

        String names [][] = new String [21][2];

        names[0][0]="Fred Grindle";
        names[0][1]="Test Male";

        names[1][0]="Emma Warber";
        names[1][1]="Test Female";

        names[2][0]="James Fletch";
        names[2][1]="Control Female";

        names[3][0]="Tom Font";
        names[3][1]="Test Male";

        names[4][0]="Dean Thatcher";
        names[4][1]="Test Male";

        names[5][0]="Harry Smith";
        names[5][1]="Control Male";

        names[6][0]="Sally Jacobs";
        names[6][1]="Control Female";

        names[7][0]="Kitty Lavinia";
        names[7][1]="Control Female";

        names[0]="Rupert Gynard";
        names[1]="Control Male";

        names[9][0]="Florence Wray";
        names[9][1]="Test Female";

        names[10][0]="Jenny Morden";
        names[10][1]="Control Female";

        names[11][0]="Will Yorter";
        names[11][1]="Test Male";

        names[12][0]="Mary Green";
        names[12][1]="Control Female";

        names[13][0]="George Handle";
        names[13][1]="Test Male";

        names[14][0]="Keely Fresh";
        names[14][1]="Control Female";

        names[15][0]="Hannah Pence";
        names[15][1]="Test Female";

        names[16][0]="Grace Dresden";
        names[16][1]="Test Female";

        names[17][0]="David Flower";
        names[17][1]="Control Male";

        names[18][0]="Lilly Fortenbleu";
        names[18][1]="Control Female";

        names[19][0]="Joe Facesdani";
        names[19][1]="Control Male";

        names[20][0]="Amy Sneeze";
        names[20][1]="Test Female";
//---------------------------------------------------------------------------------------------
        String weight [][] = new String [21][3];

        weight[0][0]="17.10";
        weight[0][1]="17.07";
        weight[0][2]="15.00";

        weight[1][0]="10.13";
        weight[1][1]="11.10";
        weight[1][2]="09.10";

        weight[2][0]="10.03";
        weight[2][1]="11.02";
        weight[2][2]="11.01";

        weight[3][0]="13.08";
        weight[3][1]="13.03";
        weight[3][2]="11.09";

        weight[4][0]="16.00";
        weight[4][1]="15.01";
        weight[4][2]="15.10";

        weight[5][0]="14.08";
        weight[5][1]="14.03";
        weight[5][2]="18.00";

        weight[6][0]="14.08";
        weight[6][1]="15.12";
        weight[6][2]="15.09";

        weight[7][0]="08.07";
        weight[7][1]="09.00";
        weight[7][2]="10.02";

        weight[0]="14.12";
        weight[1]="14.03";
        weight[2]="12.06";

        weight[9][0]="10.01";
        weight[9][1]="10.11";
        weight[9][2]="12.06";

        weight[10][0]="14.01";
        weight[10][1]="13.05";
        weight[10][2]="14.04";

        weight[11][0]="10.13";
        weight[11][1]="10.01";
        weight[11][2]="08.13";

        weight[12][0]="09.03";
        weight[12][1]="09.12";
        weight[12][2]="11.02";

        weight[13][0]="18.11";
        weight[13][1]="20.03";
        weight[13][2]="22.11";

        weight[14][0]="14.10";
        weight[14][1]="14.11";
        weight[14][2]="14.10";

        weight[15][0]="12.00";
        weight[15][1]="11.13";
        weight[15][2]="10.01";

        weight[16][0]="12.06";
        weight[16][1]="13.03";
        weight[16][2]="11.11";

        weight[17][0]="09.11";
        weight[17][1]="09.06";
        weight[17][2]="08.11";

        weight[18][0]="09.08";
        weight[18][1]="10.06";
        weight[18][2]="10.09";

        weight[19][0]="15.09";
        weight[19][1]="17.01";
        weight[19][2]="20.02";

        weight[20][0]="12.02";
        weight[20][1]="13.04";
        weight[20][2]="14.07";

        System.out.println("the values stored within the arrays are");


        System.out.println("Names \t\tCategory \t\tWeight + 5 years \tWeight +3 years \tInitial Weight");
        System.out.print("\n"+names[0][0]+ " :"+"\t\t"+ names[0][1]+"\t\t"+weight[0][0]+"\t\t\t"+weight[0][1]+"\t\t\t"+weight[0][2]);
        System.out.print("\n"+names[1][0]+ " :"+"\t\t" + names[1][1]+"\t\t"+weight[1][0]+"\t\t\t"+weight[1][1]+"\t\t\t"+weight[1][2]);
        System.out.print("\n"+names[2][0]+ " :"+"\t\t" + names[2][1]+"\t\t"+weight[2][0]+"\t\t\t"+weight[2][1]+"\t\t\t"+weight[2][2]);
        System.out.print("\n"+names[3][0]+ " :"+"\t\t" + names[3][1]+"\t\t"+weight[3][0]+"\t\t\t"+weight[3][1]+"\t\t\t"+weight[3][2]);
        System.out.print("\n"+names[4][0]+ " :"+"\t\t" + names[4][1]+"\t\t"+weight[4][0]+"\t\t\t"+weight[4][1]+"\t\t\t"+weight[4][2]);
        System.out.print("\n"+names[5][0]+ " :"+"\t\t" + names[5][1]+"\t\t"+weight[5][0]+"\t\t\t"+weight[5][1]+"\t\t\t"+weight[5][2]);
        System.out.print("\n"+names[6][0]+ " :"+"\t\t" + names[6][1]+"\t\t"+weight[6][0]+"\t\t\t"+weight[6][1]+"\t\t\t"+weight[6][2]);
        System.out.print("\n"+names[7][0]+ " :"+"\t\t" + names[7][1]+"\t\t"+weight[7][0]+"\t\t\t"+weight[7][1]+"\t\t\t"+weight[7][2]);
        System.out.print("\n"+names[0]+ " :"+"\t\t" + names[1]+"\t\t"+weight[0]+"\t\t\t"+weight[1]+"\t\t\t"+weight[2]);
        System.out.print("\n"+names[9][0]+ " :"+"\t\t" + names[9][1]+"\t\t"+weight[9][0]+"\t\t\t"+weight[9][1]+"\t\t\t"+weight[9][2]);
        System.out.print("\n"+names[10][0]+ " :"+"\t\t" + names[10][1]+"\t\t"+weight[10][0]+"\t\t\t"+weight[10][1]+"\t\t\t"+weight[10][2]);
        System.out.print("\n"+names[11][0]+ " :"+"\t\t" + names[11][1]+"\t\t"+weight[11][0]+"\t\t\t"+weight[11][1]+"\t\t\t"+weight[11][2]);
        System.out.print("\n"+names[12][0]+ " :"+"\t\t" + names[12][1]+"\t\t"+weight[12][0]+"\t\t\t"+weight[12][1]+"\t\t\t"+weight[12][2]);
        System.out.print("\n"+names[13][0]+ " :"+"\t\t" + names[13][1]+"\t\t"+weight[13][0]+"\t\t\t"+weight[13][1]+"\t\t\t"+weight[13][2]);
        System.out.print("\n"+names[14][0]+ " :"+"\t\t" + names[14][1]+"\t\t"+weight[14][0]+"\t\t\t"+weight[14][1]+"\t\t\t"+weight[14][2]);
        System.out.print("\n"+names[15][0]+ " :"+"\t\t" + names[15][1]+"\t\t"+weight[15][0]+"\t\t\t"+weight[15][1]+"\t\t\t"+weight[15][2]);
        System.out.print("\n"+names[16][0]+ " :"+"\t\t" + names[16][1]+"\t\t"+weight[16][0]+"\t\t\t"+weight[16][1]+"\t\t\t"+weight[16][2]);
        System.out.print("\n"+names[17][0]+ " :"+"\t\t" + names[17][1]+"\t\t"+weight[17][0]+"\t\t\t"+weight[17][1]+"\t\t\t"+weight[17][2]);
        System.out.print("\n"+names[18][0]+ " :"+"\t" + names[18][1]+"\t\t"+weight[18][0]+"\t\t\t"+weight[18][1]+"\t\t\t"+weight[18][2]);
        System.out.print("\n"+names[19][0]+ " :"+"\t\t" + names[19][1]+"\t\t"+weight[19][0]+"\t\t\t"+weight[19][1]+"\t\t\t"+weight[19][2]);
        System.out.print("\n"+names[20][0]+ " :"+"\t\t" + names[20][1]+"\t\t"+weight[20][0]+"\t\t\t"+weight[20][1]+"\t\t\t"+weight[20][2]+"\n\n");

in opposite world i love programming
 
Old December 19th, 2007, 08:51 AM
Authorized User
 
Join Date: Nov 2007
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to chris1012
Default

at the end of the day the program is a conversion program which converts from metric to imperial weights stones/lbs pounds to kilograms what i planned on doing was creating a gui i planned on using the joption pane which displayed the values stored within the arrays with case statements so when compiled a gui would pop up with a case statement an example is shown below to show you what i mean

import javax.swing.*;

public class MultiIfElse
{
    public static void main(String[] args)
    {
        new MultiIfElse();
    }

    public MultiIfElse()
    {
        String number = JOptionPane.showInputDialog("Choose a Pizza:\n1)Ham\n2)Frog\n3)Hedgehog\n4)Fried Hippopottomas\n5)Peanut Butter\n6)Griddled Flamingo\n7)Albatross\n8)Girraffe and Bacon\n9)Newt and Toad\n10)Road Kill");
        int num = Integer.parseInt(number);
        String pizza = "";
        switch(num)
        {
        case 1:
                pizza="Ham";
                break;
        case 2:
                pizza="Frog";
                break;
        case 3:
                pizza="Hamster";
                break;
        case 4:
                pizza="Fried Hippopottomas";
                break;
        case 5:
                pizza="Peanut Butter";
                break;
        case 6:
                pizza="grilled Flamingo";
                break;
        case 7:
                pizza = "Albatross";
                break;
        case 8:
                pizza = "Girraffe and Bacon";
                break;
        case 9:
                pizza = "Newt and Toad";
                break;
        case 10:
                pizza = "Road Kill";
                break;
        default:
                pizza ="Default";
                break;

        }
        JOptionPane.showMessageDialog(null,"Your pizza was "+pizza+". Don't choke on the chewie bits");
        JOptionPane.showMessageDialog(null,"Thankyou Goodbye");
        System.exit(0);
    }
}


in opposite world i love programming
 
Old December 22nd, 2007, 01:11 PM
Authorized User
 
Join Date: Dec 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default


        names[20][0]="Amy Sneeze";
        names[20][1]="Test Female";
//---------------------------------------------------------------------------------------------
        String weight [][] = new String [21][3];

        weight[0][0]="17.10";
        weight[0][1]="17.07";
        weight[0][2]="15.00";


        weight[1][0]="10.13";
        weight[1][1]="11.10";
        weight[1][2]="09.10";

        Double parseMe = Double.parseDouble(weight[1][0]);
        System.out.print(":::::::: " + weight[1][0] + " :::::");

        weight[2][0]="10.03";
        weight[2][1]="11.02";
        weight[2][2]="11.01";

        weight[3][0]="13.08";
        weight[3][1]="13.03";
        weight[3][2]="11.09";







Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Add Muti-Media control in asp.net dharmeshtandel VBScript 0 March 29th, 2008 04:22 AM
1 and 2 dimensional arrays jeff_cafm VB.NET 2002/2003 Basics 1 April 26th, 2006 05:02 PM
1 and 2 dimensional arrays jeff_cafm VB.NET 1 April 24th, 2006 03:05 PM
Multidemmesional Arrays OR arrays gmoney060 Classic ASP Basics 3 November 1st, 2004 03:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.