🔒 Closed Need Codes po ng java netbean for displaying employee name and there department

Status
Not open for further replies.

rome22

Grasshopper
Mga lods I am just helping a friend since na hindi ako familiar sa javascript more on c++ coding ako lods please see picture for details
 

Attachments

  • received_330098631295360.webp
    received_330098631295360.webp
    23.8 KB · Views: 17
eto ts pa try nalang
Java:
public class Rome22
{
   public static void main(String[] args) {
       String employee [][] = {            
                //employee
                {"Zuch ", "Huhg ", "Adam ", "Nathan ", "Erick "},
                //department
                {"SITE ", "CN ", "COE ", "CBAA ", "CEDE "},
            };
       int column = 5;
       int row = 1;
       //Save the 2D array into 1D array but only the names
       String[] employee1D = new String[column];
       int it = 0;
       for(int i = 0; i < row ; i++) {
           for(int j = 0 ; j < column ; j++) {
               employee1D[it] = employee[i][j];
               it++;
           }
       }
       //Sort the 1D array
       for(int i = 0 ; i < employee1D.length - 1; i++) {
           for(int j = i + 1 ; j < employee1D.length ; j++) {
               if(employee1D[i].compareTo(employee1D[j]) > 0) {
                   String temp = employee1D[i];
                   employee1D[i] = employee1D[j];
                   employee1D[j] = temp;
               }
           }
       }
       //Print the 2D sorted Array
       System.out.println("Name\t\t\tDepartment");
       int x = 0; // use to iterate the 1D array
       for(int i = 0 ; i <= 2 ; i++) {
           for(int j = 0 ; j < column; j++) {
               //Check if the Sorted 1D array is equal to the names in 2D array to get the corresponding Department
               if(employee[0][j].equals(employee1D[x])) {
               System.out.println(employee1D[x] +"\t\t\t"+ employee[1][j]);
               if(x < 4)
                   x++;
          }
       }
    }
  }
}
 
eto ts pa try nalang
Java:
public class Rome22
{
   public static void main(String[] args) {
       String employee [][] = {           
                //employee
                {"Zuch ", "Huhg ", "Adam ", "Nathan ", "Erick "},
                //department
                {"SITE ", "CN ", "COE ", "CBAA ", "CEDE "},
            };
       int column = 5;
       int row = 1;
       //Save the 2D array into 1D array but only the names
       String[] employee1D = new String[column];
       int it = 0;
       for(int i = 0; i < row ; i++) {
           for(int j = 0 ; j < column ; j++) {
               employee1D[it] = employee[i][j];
               it++;
           }
       }
       //Sort the 1D array
       for(int i = 0 ; i < employee1D.length - 1; i++) {
           for(int j = i + 1 ; j < employee1D.length ; j++) {
               if(employee1D[i].compareTo(employee1D[j]) > 0) {
                   String temp = employee1D[i];
                   employee1D[i] = employee1D[j];
                   employee1D[j] = temp;
               }
           }
       }
       //Print the 2D sorted Array
       System.out.println("Name\t\t\tDepartment");
       int x = 0; // use to iterate the 1D array
       for(int i = 0 ; i <= 2 ; i++) {
           for(int j = 0 ; j < column; j++) {
               //Check if the Sorted 1D array is equal to the names in 2D array to get the corresponding Department
               if(employee[0][j].equals(employee1D[x])) {
               System.out.println(employee1D[x] +"\t\t\t"+ employee[1][j]);
               if(x < 4)
                   x++;
          }
       }
    }
  }
}
Thanks lods your da best 👌
 
Status
Not open for further replies.

About this Thread

  • 10
    Replies
  • 451
    Views
  • 4
    Participants
Last reply from:
rome22

Trending Topics

Online now

Members online
1,110
Guests online
1,733
Total visitors
2,843

Forum statistics

Threads
2,268,530
Posts
28,922,558
Members
1,242,960
Latest member
kazpog93
Back
Top