Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

1 Visitor Messages

  1. View Conversation
    Hello. Can you please help me? I need to get the same output as this program using an if statement. What the program does is that, it initializes values for a 2d array named employeeInfo. Then it prompts the user to input an idNumber. The condition must be, if idNumber is equal to 1(which is the value of employeeInfo[0][0]), then it will print the values of employeeInfo[0][1] and employeeInfo[0][2]. Same for the others. If idNumber is 2, then it will print Eunice 50,000, and if idNumber is 3, it will print Diane 70,000. I really hope you can help me. I'm a beginner in java. Godbless



    import javax.swing.JOptionPane;

    public class Assignment2{
    public static void main(String[] args){

    String[][] employeeInfo ={{"1","Mira","100,000"},
    {"2","Eunice","50,000"},
    {"3","Diane","70,000"}};

    String idNumber="";
    idNumber=JOptionPane.showInputDialog("Please enter employee idNumber:");

    switch(idNumber)
    {
    case "1":
    for(int i=0;i<employeeInfo.length;i++)
    {
    for(int j=1;j<employeeInfo[i].length;j++)
    {
    System.out.println(employeeInfo[i][j]);

    }
    break;
    }
    break;

    case "2":
    for(int i=1;i<employeeInfo.length;i++)
    {
    for(int j=1;j<employeeInfo[i].length;j++)
    {
    System.out.println(employeeInfo[i][j]);
    }
    break;
    }
    break;

    case "3":
    for(int i=2;i<employeeInfo.length;i++)
    {
    for(int j=1;j<employeeInfo[i].length;j++)
    {
    System.out.println(employeeInfo[i][j]);
    }

    }
    break;

    default:
    System.out.println("You entered an invalid idNumber!");

    break;

    }
    }
    }
Showing Visitor Messages 1 to 1 of 1
About John Joe

Basic Information

Age
26
About John Joe
Java Skill Level:
Beginner

Signature


Whatever you are, be a good one

Statistics


Total Posts
Total Posts
252
Posts Per Day
0.33
Visitor Messages
Total Messages
1
Most Recent Message
September 17th, 2017 02:32 AM
Total Thanks
Total Thanks
8
  • Thanked 17 Times in 17 Posts
General Information
Last Activity
Yesterday 02:18 AM
Join Date
June 15th, 2017

3 Friends

  1. MiraMarcos MiraMarcos is offline

    Junior Member

    MiraMarcos
  2. RAS ABERGA RAS ABERGA is offline

    Junior Member

    RAS ABERGA
  3. Snipe Snipe is offline

    Junior Member

    Snipe
Showing Friends 1 to 3 of 3