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 19th, 2007, 02:52 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 trying to show an array

hey guys am working on a conversion program at the minute just messing really and i was wondering how i could get this damn thing working what i've got is a **** load of data in to multidimensional arrays 1 2 dimensional one and 1 3 dimensional one well heres what i've got any way.


what am trying to acomplish here is to setup a joption pain gui which when say a user enters a number it brings up a value within my miltidimensional array this may seem completely basic to u but bare in mind i am a noobie:D
import javax.swing.*;

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




    public arraytest()
    {

        /*aray of names and categories defined*/
        String names [][] = new String [3][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";




        String number = JOptionPane.showInputDialog("Please enter a number which resembles the weight value you wish to be converted\n Name\t\t Weight 1\t\t Weight 2\t\tweight 3");
        int num = Integer.parseInt(number);
        String names = "";
        switch(num)
        {
        case 1:
                names="Fred Grindle";
                break;
        case 2:
                names="Emma Warber";
                break;
        case 3:
                names="James Fletch";
                break;

        }
        JOptionPane.showMessageDialog(null,"the name you chose was"+names);
        JOptionPane.showMessageDialog(null,"Thankyou Goodbye");
        System.exit(0);
    }
}


in opposite world i love programming
__________________
in opposite world i love programming
 
Old December 21st, 2007, 03:13 PM
Authorized User
 
Join Date: Jul 2006
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ironchef
Default

I dont really get what your asking but to iterate(go through) the items in an array, u can use a 'for' loop.

IronChef - http://www.freewebs.com/cool_recipes
 
Old December 22nd, 2007, 12:57 PM
Authorized User
 
Join Date: Dec 2007
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

    {

        /*aray of names and categories defined*/
        String names [][] = new String [3][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";




        String number = JOptionPane.showInputDialog("Please enter a number which resembles the weight value you wish to be converted\n Name\t\t Weight 1\t\t Weight 2\t\tweight 3");
        int num = Integer.parseInt(number);
        String names1 = "";
        switch(num)
        {
        case 1:
                names1="Fred Grindle";
                break;
        case 2:
                names1="Emma Warber";
                break;
        case 3:
                names1="James Fletch";
                break;

        }
        JOptionPane.showMessageDialog(null,"the name you chose was"+names1);
        JOptionPane.showMessageDialog(null,"Thankyou Goodbye");
        System.exit(0);
    }







Similar Threads
Thread Thread Starter Forum Replies Last Post
Convering a String Array to an Integer array nkrust C# 9 November 17th, 2010 12:02 PM
Go from 2d Array to 1d array without defining type OneQuestion General .NET 1 January 10th, 2008 11:13 AM
error when sorting an Array of Array nancy VBScript 2 February 17th, 2005 12:57 PM
Passing php array values to javascript array gkrishna Pro PHP 0 November 6th, 2004 03:20 AM
Array to Array comparison pavel Pro VB 6 0 March 24th, 2004 06:33 PM





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