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.

Conversation Between MiraMarcos and John Joe

2 Visitor Messages

  1. hi
  2. 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 2 of 2