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.

Results 1 to 3 of 3

Thread: Hello, Need Help Please.

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Hello, Need Help Please.

    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;

    }
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Hello, Need Help Please.

    using an if statement.
    What have you tried? What problems are you having?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2017
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hello, Need Help Please.

    Hi MiraMarcos,
    is this what you want?

    See: http://www.javaprogrammingforums.com...n-feeding.html
    Last edited by Norm; September 21st, 2017 at 10:46 AM. Reason: Please don't spoonfeed code for OPs

Tags for this Thread