By GokiSoft.com| 15:27 09/11/2022|
Java Advanced

Phân chia mảng số nguyên thành 2 phần + chắc + lẻ

Câu 1: Nhập mảng số nguyên gồm N phần tử (khai báo theo cách int[] t = new int[N]). Thực hiện chuyển các số chẵn sang bên trái và số lẻ sang bên phải theo thứ tự tăng dần

Ví du: mảng nhập vào [1, 9, 2, 7, 10, 4, 5, 6]

Kết quả mảng [2, 4, 6, 10, 1, 5, 7, 9]

Câu 2: Tạo đối tượng sinh viên gồm các thuộc tính sau >> Tên, tuổi, địa chỉ, email, số điện thoại. 

Trong class Main tạo 2 đối tượng sinh viên stdA và stdB. Kiểm tra xem trong các thuộc tính của 2 sinh viên => xuất hiện chuỗi searching (chuỗi này được nhập từ bàn phím).



Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Lê Minh Bắc [T1907A]
Lê Minh Bắc

2020-05-11 08:00:39

ĐỀ 2:

Câu 1:

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ISA.Cau1;

import java.util.Scanner;

/**
 *
 * @author lemin
 */
public class Main {
    public static void main(String[] args) {
    int N, c, d;
    Scanner scan = new Scanner(System.in);
         
    do {
        System.out.print("Nhập vào số phần tử của mảng: ");
        N = scan.nextInt();
    } while (N <= 0);
         
    int[] t = new int[N];
    int[] ch = new int[N];  // mảng chứa các phần tử là số chẵn
    int[] le = new int[N];  // mảng chứa các phần tử là số lẻ
         
    System.out.println("Nhập các phần tử cho mảng: ");
    for (int i = 0; i < N; i++) {
        System.out.print("Nhập phần tử thứ " + i + ": ");
        t[i] = scan.nextInt();
    }
         
    // c: số phần tử của mảng ch
    // d: số phần tử của mảng le.
    c = d = 0;
         
    for (int i = 0; i < N; i++) {
        // nếu phần tử tại vị trí i chia hết cho 2 thì gán phần tử đó cho phần tử tại vị trí c của mảng ch
        // ngược lại thì gán phần tử đó cho phần tử tại vị trí d của mảng le
        if (t[i] % 2 == 0) {
            ch[c] = t[i];
            c++;
        } else {
            le[d] = t[i];
            d++;
        }
    }
         
    sortASC(ch);    //sắp xếp mảng các số chẵn
    sortASC(le);    //sắp xếp mảng các số lẻ
    System.out.println("Mảng sau khi sắp xếp");
    display(ch);
    display(le);
    }
    
    public static void sortASC(int [] array) {
        // Hàm sắp xếp theo thứ tự tăng dần
        int temp = array[0];
        for (int i = 0 ; i < array.length - 1; i++) {
            for (int j = i + 1; j < array.length; j++) {
                if (array[i] > array[j]) {
                    temp = array[j];
                    array[j] = array[i];
                    array[i] = temp;
                }
            }
        }
    }
    
    public static void display(int [] array) {
        // Hàm hiển thị
        for (int i = 0; i < array.length; i++) {
            if(array[i] != 0)  
            System.out.print(array[i] + " ");
        }
    }
}

Câu 2:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ISA.Cau2;

/**
 *
 * @author lemin
 */
public class Student {
    String name;
    int age;
    String address, email, phonenumber;

    public Student(String name, int age, String address, String email, String phonenumber) {
        this.name = name;
        this.age = age;
        this.address = address;
        this.email = email;
        this.phonenumber = phonenumber;
    }

    public Student() {
    }

    public void display() {
        System.out.println("Tên: " + name);
        System.out.println("Tuổi: " + age);
        System.out.println("Địa chỉ: " + address);
        System.out.println("email: " + email);
        System.out.println("Số điện thoại: " + phonenumber);
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ISA.Cau2;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author lemin
 */
public class Main {
    public static void main(String[] args) {
        Student stdA = new Student ("Le Minh Bac",19,"Ha Noi","leminhbac2001@gmail.com","0965975836");
        Student stdB = new Student ("Doan Linh Dan",17,"Quang Binh","doanlinhdan2003@gmail.com","1234567890");
        List<Student> studentList;
        
        studentList = new ArrayList<>();
        studentList.add(stdA);
        studentList.add(stdB);
        
        System.out.println("Tìm kiếm sinh viên: ");
        System.out.print("Nhập tên sinh viên cần tìm: ");
        Scanner scan = new Scanner(System.in);
        String search = scan.nextLine();
        if(search.equalsIgnoreCase(stdA.name)){
            stdA.display();
        }else if(search.equalsIgnoreCase(stdB.name)){
            stdB.display(); 
        } else {
            System.out.println("Không tìm thấy sinh viên!!!");
        }
    }
}



hoangduyminh [T1907A]
hoangduyminh

2020-05-11 08:00:04



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package less10;

import java.util.Scanner;

/**
 *
 * @author Minh
 */
public class Main {
    public static void main(String[] args) {
        int n,c,d;
        Scanner scanner = new Scanner(System.in);
        
        do {            
            System.out.println("Nhap Vao So Phan Tu Trong Mang:");
            n = scanner.nextInt();
        } while (n <=0);
        
        int t[] = new int[n];
        int chan[] = new int[n];
        int le[] = new int[n];
        
        System.out.println("Nhap vao cac phan tu trong mang");
        for (int i = 0; i < n; i++) {
            System.out.println("Nhap phần tử thứ " +i + ":");
            t[i] = scanner.nextInt();
        }
        
        c = d =0;
        
        for (int i = 0; i < n; i++) {
            if(t[i] %2 == 0){
              chan[c] = t[i];
              c++;
            }else{
              le[d] = t[i];
              d++;
            }
        }
        System.out.println("\nCac số mảng chẵn là:");
        for (int i = 0; i < c; i++) {
            System.out.println(chan[i]+"\t");
        }
        System.out.println("\nCac sống mảng lẻ là:");
        for (int i = 0; i < d; i++) {
            System.out.println(le[i] + "\t");
        }
    }
    
    
}

Bai 1



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession9;

import java.util.Scanner;

/**
 *
 * @author Minh
 */
public class Student {
    String name,address,email,phonenumber;
    int age;

    public Student() {
    }

    public Student(String name, String address, String email, String phonenumber, int age) {
        this.name = name;
        this.address = address;
        this.email = email;
        this.phonenumber = phonenumber;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhonenumber() {
        return phonenumber;
    }

    public void setPhonenumber(String phonenumber) {
        this.phonenumber = phonenumber;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" + "name=" + name + ", address=" + address + ", email=" + email + ", phonenumber=" + phonenumber + ", age=" + age + '}';
    }
    
    public void display() {
        System.out.println(toString());
    }
    
    public void input() {
        Scanner input = new Scanner(System.in);
        
        System.out.println("Nhap vao ten sv:");
        name = input.nextLine();
        System.out.println("Nhap vao địa chỉ của sv:");
        address = input.nextLine();
        System.out.println("Nhap vao email của sv:");
        email = input.nextLine();
        System.out.println("Nhap vao phonenumber :");
        phonenumber = input.nextLine();
        System.out.println("Nhap vao tuoi sv:");
        age = Integer.parseInt(input.nextLine());
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package lession9;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Minh
 */
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        List<Student> student = new ArrayList<>();
        
        Student std1 = new Student();
        Student std2 = new Student();
        
        int choose;
        do {
               showMenu();
               choose = scan.nextInt();
               switch (choose){
                   case 1:
                       System.out.println("Nhập vào thông tin sinh viên:");
                       int n = scan.nextInt();
                       for (int i = 0; i < n; i++) {
                           Student std = new Student();
                           std.input();
                       }
                       break;
                   case 2:
                       
                       break;
                   case 3:
                       break;
                   case 4:
                       System.out.println("Thoat!!");
                       break;
                   default:
                       System.out.println("Nhap lỗi mời nhập lại!!");
                       break;
                  
               }
            
        } while (choose !=4);
    }
    public static void showMenu() {
        System.out.println("1.Nhap vao n sinh vien");
        System.out.println("Hien Thi thong tin sinh vien");
        System.out.println("Tim kiem theo ma sinh vien");
        System.out.println("Thoat..");
        System.out.println("Nhap lữa chọn");
      
    }
}
B2



Trương Công Vinh [T1907A]
Trương Công Vinh

2020-05-11 07:58:06



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ExamISA;

/**
 *
 * @author DELL
 */
public class Student {
    String ten, diachi, email, sdt;
 int  tuoi;
    public Student(String ten, int   tuoi, String diachi, String email, String sdt) {
        this.ten = ten;
        this.tuoi = tuoi;
        this.diachi = diachi;
        this.email = email;
        this.sdt = sdt;
    }

    public Student() {
    }

    public String getTen() {
        return ten;
    }

    public void setTen(String ten) {
        this.ten = ten;
    }

    public int   getTuoi() {
        return tuoi;
    }

    public void setTuoi(int   tuoi) {
        this.tuoi = tuoi;
    }

    public String getDiachi() {
        return diachi;
    }

    public void setDiachi(String diachi) {
        this.diachi = diachi;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getSdt() {
        return sdt;
    }

    public void setSdt(String sdt) {
        this.sdt = sdt;
    }

    @Override
    public String toString() {
        return "Student{" + "ten=" + ten + ", diachi=" + diachi + ", email=" + email + ", sdt=" + sdt + ", tuoi=" + tuoi + '}';
    }
    
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ExamISA;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class Cau2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        ArrayList<Student> std = new ArrayList<>();
        Student std1 = new Student("Tran van a", 15, "ABC XYZ", "EmailA@gmail.com", "0122221");
        Student std2 = new Student("Tran van b", 18, "ABCD XYZ", "EmailB@gmail.com", "015545422221");
        std.add(std2);
        std.add(std1);
        System.out.println("Searching : ");
        String searching = scan.nextLine();
        for (Student student : std) {
            if (student.getDiachi().contains(searching)||
                    student.getEmail().contains(searching)||
                    student.getSdt().contains(searching)||
                    student.getTen().contains(searching)||
                    student.getTuoi() == Integer.parseInt(searching)) {
                System.out.println(student.toString());
            }else{
                break;
            }
        }
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ExamISA;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class Cau1 {
    static Scanner scan = new Scanner(System.in);
    public static void main(String[] args) {
        
        System.out.println("nhap so luong phan tu can nhap cua mang : ");
        int n =Integer.parseInt(scan.nextLine());
        int[] t = new int[n];
        t = createArray(n);
        
        int[] chan = new  int[n];
        int[] le = new  int[n];
        for (int i = 0; i < t.length; i++) {
            if (t[i] % 2 == 0 ) {
                chan = addElement(chan, t[i]);
            }else{
                le = addElement(le,  t[i]);
            }
        }
        sortASC(le);
        sortASC(chan);
        
        int[] kq = new int[n];
        for (Integer integer : chan) {
            kq = addElement(kq, integer);
        }
          for (Integer integer : le) {
            kq = addElement(kq, integer);
        }
          
          show(kq);
          
        
        
        
    }
    static int[] createArray(int n){
        int[] t = new int[n];
        ArrayList<Integer>  list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            System.out.println(" nhap phan tu thu "+(i+1) + " : ");
          int  a = Integer.parseInt(scan.nextLine());
            t = addElement(t, a);
        }
        
        return t;
    } 
    static int[] addElement(int[] a, int e) {
    a  = Arrays.copyOf(a, a.length + 1);
    a[a.length - 1] = e;
    return a;
}
     public static void sortASC(int [] arr) {
        int temp = arr[0];
        for (int i = 0 ; i < arr.length - 1; i++) {
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[i] > arr[j]) {
                    temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }
        }
    }
    public static void show(int [] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }
}



NguyenHuuThanh [T1907A]
NguyenHuuThanh

2020-05-11 07:57:08



B1
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javatestapplication;

import java.util.Scanner;

/**
 *
 * @author abc
 */
public class JavaTestApplication {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int N ;
        Scanner scan = new Scanner(System.in);
        N = Integer.parseInt(scan.nextLine());
        int[] intArray = new int[N] ;
        int numberofodd = 0 ;
        int[] intArray01 = new int[N];
        
        for ( int i = 0 ; i < N ; i++ )
        {
            intArray[i] = scan.nextInt();
        }
        
        for ( int i = 0 ; i < intArray.length ; i++)
        {
            if ( intArray[i]%2 == 1)
            {
                numberofodd++;
            }
        }
        // sort tang dan 
        for ( int i = 0 ; i < N - 1 ; i++ )
        {
            for ( int j = 0 ; j < N - 1 - i ; j++ )
            {
                if( intArray[j] > intArray[j+1] )
                {
                    int temp = intArray[j];
                    intArray[j] = intArray[j+1];
                    intArray[j+1] = temp;
                }
            }
        }
        
        
        for ( int i = 0 ; i < N ; i++)
        {
            System.out.println(intArray[i]);
            
        }
        System.out.println("end");
        
        int m = 0 ;
        int n = N - numberofodd;
        
        for ( int i = 0 ; i < N ; i++)
        {
            if (intArray[i]%2 == 0)
            {
                if ( m < N - numberofodd)
                {
                    intArray01[m++] = intArray[i];
                }
            }
            else
            {
                if ( n < N )
                {
                    intArray01[n++] = intArray[i];
                }
            }
        }
        
        
        for ( int i = 0 ; i < N ; i++)
        {
            intArray[i] = intArray01[i];
            System.out.println(intArray[i]);
            
        }
        System.out.println("end");
    }
   
    
}
B2
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javatestapplication;

import java.util.Scanner;

/**
 *
 * @author abc
 */
public class Main {
    public static void main(String[] args)
    {
        Student stdA = new Student();
        Student stdB = new Student();
        stdA.input();
        stdB.input();
        
        String searching;
        Scanner scan = new Scanner(System.in);
        
        
        int choice ;
        
        do
        {
            showmenu();
            choice = Integer.parseInt(scan.nextLine());
            
            switch(choice)
            {
                case 1 :
                    searching = scan.nextLine();
                    if(searching.equals(stdA.getName()))
                    {
                        stdA.display();
                    }
                    else if (searching.equals(stdB.getName()))
                    {
                        stdB.display();
                    }
                    else
                    {
                        System.out.println("Khong trùng tên");
                    }
                    break;
                case 2 :
                    searching = scan.nextLine();
                    if(searching.equals(stdA.getAddress()))
                    {
                        stdA.display();
                    }
                    else if (searching.equals(stdB.getAddress()))
                    {
                        stdB.display();
                    }
                    else
                    {
                        System.out.println("Khong trùng địa chỉ");
                    }
                    break;
                    
                case 3 : 
                    searching = scan.nextLine();
                    if(searching.equals(stdA.getEmail()))
                    {
                        stdA.display();
                    }
                    else if (searching.equals(stdB.getEmail()))
                    {
                        stdB.display();
                    }
                    else
                    {
                        System.out.println("Khong trùng email");
                    }
                    break;
                    
                case 4 :
                    searching = scan.nextLine();
                    if(searching.equals(stdA.getPhonenumber()))
                    {
                        stdA.display();
                    }
                    else if (searching.equals(stdB.getPhonenumber()))
                    {
                        stdB.display();
                    }
                    else
                    {
                        System.out.println("Khong trùng phonenumber");
                    }
                    break;
                   
                case 5 :
                    int searching01 = Integer.parseInt(scan.nextLine());
                    if(searching01 == stdA.getAge())
                    {
                        stdA.display();
                    }
                    else if (searching01 == stdB.getAge())
                    {
                        stdB.display();
                    }
                    else
                    {
                        System.out.println("Khong trùng tuổi");
                    }
                    break;
                    
                case 6 :
                    System.out.println("exit");
                default :
                    System.out.println("break");
                    break;
                 
            }
        }while(choice != 6);
        
        
    }
    public static void showmenu()
    {
        System.out.println("1. search tên");
        System.out.println("2. search address");
        System.out.println("3. search email");
        System.out.println("4. search phonenumber");
        System.out.println("5. search age");
        System.out.println("6. exit");
    }
    
}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javatestapplication;

import java.util.Scanner;

/**
 *
 * @author abc
 */
public class Student {
    String name , address , email , phonenumber;
    int age;
    
    public Student()
    {
        
    }

    public Student(String name, String address, String email, String phonenumber, int age) {
        this.name = name;
        this.address = address;
        this.email = email;
        this.phonenumber = phonenumber;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhonenumber() {
        return phonenumber;
    }

    public void setPhonenumber(String phonenumber) {
        this.phonenumber = phonenumber;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" + "name=" + name + ", address=" + address + ", email=" + email + ", phonenumber=" + phonenumber + ", age=" + age + '}';
    }
    public void input()
    {
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap ten :");
        name = scan.nextLine();
        System.out.println("Nhap address");
        address = scan.nextLine();
        System.out.println("Nhap email");
        email = scan.nextLine();
        System.out.println("Nhap phonenumber");
        phonenumber = scan.nextLine();
        System.out.println("Nhap age");
        age = Integer.parseInt(scan.nextLine());
        
    }
    public void display()
    {
        System.out.println(toString());
    }
    
    
}




Trần Mạnh Dũng [T1907A]
Trần Mạnh Dũng

2020-05-11 07:55:51

Đề 2: không làm đươc câu 2 


#ISA_T1907A.java


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package isa_t1907a;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

/**
 *
 * @author admin
 */
public class ISA_T1907A {

    static Scanner scan = new Scanner(System.in);

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.print("Enter the number of elements in the array: ");
        int a = Integer.parseInt(scan.nextLine());
        int[] t = new int[a];
        t = Array(a);
        int[] even = new int[a];
        int[] odd = new int[a];
        int[] main = new int[a];
        for (int i = 0; i < t.length; i++) {
            if (t[i] % 2 == 0) {
                even = Element(even, t[i]);
            } else {
                odd = Element(odd, t[i]);
            }
        }

        for (Integer integer : even) {
            main = Element(main, integer);
        }
        for (Integer integer : odd) {
            main = Element(main, integer);
        }
        sapxeptangdan(even);
        sapxeptangdan(odd);

        Hienthi(main);
    }

    static void sapxeptangdan(int[] List) {
        int temp = List[0];
        for (int i = 0; i < List.length - 1; i++) {
            for (int j = i + 1; j < List.length; j++) {
                if (List[i] > List[j]) {
                    temp = List[j];
                    List[j] = List[i];
                    List[i] = temp;
                }
            }
        }
    }

    public static int[] Array(int a) {
        int[] t = new int[a];
        ArrayList<Integer> List = new ArrayList<>();
        for (int i = 0; i < a; i++) {
            System.out.print("Enter the element " + (i + 1) + " :");
            int s = Integer.parseInt(scan.nextLine());
            t = Element(t, s);
        }

        return t;
    }

    public static int[] Element(int[] a, int e) {
        a = Arrays.copyOf(a, a.length + 1);
        a[a.length - 1] = e;
        return a;
    }

    public static void Hienthi(int[] arr) {
        System.out.println("Show:");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+",");
        }
    }
}



nguyễn văn huy [T1907A]
nguyễn văn huy

2020-05-11 07:52:19



câu 1:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package chanle;

/**
 *
 * @author ASUS
 */
public class main {
    public static void main(String[] args) {
        int[] num = {1, 2, 3, 4, 5, 6, 7, 8, 9};
        String[] arrEvent = new String[num.length];
        String[] arrOdd = new String[num.length];
         
        int loop = 0;     
        int index = 0;
        for (int i = 0; i < num.length; i++) {
            loop++;
            if (num[i] % 2 == 0){
                arrEvent[index] = "" + num[i];
                index++;
            }
        }        
        index = 0;
        for (int i = 0; i < num.length; i++) {
            loop++;
            if (num[i] % 2 != 0){
                arrOdd[index] = "" + num[i];
                index++;
            }
        }   
        for (int i = 0; i < arrEvent.length; i++){
            loop++;
            if (arrEvent[i] == null){
                break;
            }
            num[i] = Integer.parseInt(arrEvent[i]);
        }       
        for (int i = 0; i < arrOdd.length; i++){
            loop++;
            if (arrOdd[i] == null){
                break;
            }
            num[num.length- i - 1] = Integer.parseInt(arrOdd[i]);
        }
        System.out.println("loop count: " + loop);
        for (int i = 0; i < num.length; i++) {
            System.out.println(num[i]);
        }
    }
}
??????
câu 2:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sinhvienn;

import java.util.Scanner;

/**
 *
 * @author ASUS
 */
public class sinhlip {
    String ten,diachi,email;
    int tuoi,sdt;

    public sinhlip() {
    }

    public sinhlip(String ten, String diachi, String email, int tuoi, int sdt) {
        this.ten = ten;
        this.diachi = diachi;
        this.email = email;
        this.tuoi = tuoi;
        this.sdt = sdt;
    }
    public void input(){
        Scanner scan=new Scanner(System.in);
        System.out.println("nhap ten:");
        ten=scan.nextLine();
        System.out.println("nhap tuoi:");
        tuoi=Integer.parseInt(scan.nextLine());
        System.out.println("nhap dia chi:");
        diachi=scan.nextLine();
        System.out.println("nhap email:");
        email=scan.nextLine();
        System.out.println("nhap sdt:");
        sdt=Integer.parseInt(scan.nextLine());
    }
    public void display(){
        System.out.println(toString());
    }

    public String getTen() {
        return ten;
    }

    public void setTen(String ten) {
        this.ten = ten;
    }

    public String getDiachi() {
        return diachi;
    }

    public void setDiachi(String diachi) {
        this.diachi = diachi;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getTuoi() {
        return tuoi;
    }

    public void setTuoi(int tuoi) {
        this.tuoi = tuoi;
    }

    public int getSdt() {
        return sdt;
    }

    public void setSdt(int sdt) {
        this.sdt = sdt;
    }
    
}
....
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sinhvienn;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author ASUS
 */
public class main {
    public static void main(String[] args) {
        List<sinhlip> thaolist = new ArrayList<>();
        int choise, n;
        Scanner scan = new Scanner(System.in);
        do {            
            menu();
            choise=Integer.parseInt(scan.nextLine());
            switch(choise){
                case 1:
                    System.out.println("nhap so sinh vien");
                    n=Integer.parseInt(scan.nextLine());
                    for (int i = 0; i < n; i++) {
                        sinhlip thao=new sinhlip();
                        thao.input();
                        thaolist.add(thao);
                    }
                    break;
                case 2:
                    for (sinhlip thao : thaolist) {
                        thao.display();
                    }
                    break;
                case 3:
                    System.out.println("nhap email cần tìm kiếm");
                    String email=scan.nextLine();
                    for (int i = 0; i <thaolist.size(); i++) {
                        if(thaolist.get(i).getEmail().equalsIgnoreCase(email)){
                            thaolist.get(i).display();
                        }
                    }
                    break;
            }
        } while (choise!=3);
    }
    static void menu(){
        System.out.println("1.nhập thông tin sinh viên:");
        System.out.println("2.hiển thị");
        System.out.println("3.tìm kiếm");
    }
}



thienphu [T1907A]
thienphu

2020-05-11 07:49:23

BT1


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BaiThi1;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class BT1 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap vao N phan tu ");
        int n = Integer.parseInt(input.nextLine());

        int[] mang = new int[n];
        for (int i = 0; i < mang.length; i++) {
            System.out.println("Nhap phan tu : " + (i + 1));
            int number = Integer.parseInt(input.nextLine());

            mang[i] = number;
        }

        sortASC(mang);
        System.out.println("Danh sach can hien thi sau khi sap xep la: ");
        for (int i = 0; i < mang.length; i++) {
            System.out.print(mang[i] + " ; ");
        }

    }

    public static void sortASC(int[] arr) {

        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = i + 1; j < arr.length; j++) {

                if ((arr[i] % 2 != 0 && arr[j] % 2 == 0)
                        || (arr[i] % 2 == 0 && arr[j] % 2 == 0 && arr[i] > arr[j])
                        || (arr[i] % 2 != 0 && arr[j] % 2 != 0 && arr[i] > arr[j])) {
                    int index = arr[i];
                    arr[i] = arr[j];
                    arr[j] = index;
                }

            }
        }
    }
}

BT2



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BaiThi1;

import java.util.Scanner;

/**
 *
 * @author Thien Phu
 */
public class Student {

    private String name, address, email;
    private int age, phone;

    public Student() {
    }

    public Student(String name, int age, String address, String email, int phone) {
        this.name = name;
        this.address = address;
        this.age = age;
        this.phone = phone;
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getPhone() {
        return phone;
    }

    public void setPhone(int phone) {
        this.phone = phone;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getEmail() {
        return email;
    }

    @Override
    public String toString() {
        return "Student{" + "name=" + name + ", address=" + address + ", email=" + email + ", age=" + age + ", phone=" + phone + '}';
    }

    public boolean isCheckString() {
        String search = toString();

        if (search.contains("searching")) {
            return true;
        }
        return false;
    }

    public void inputStudent() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập thông tin sinh vien");
        System.out.println("Nhâp ten sv: ");
        name = input.nextLine();
        System.out.println("Nhap tuổi sinh viên");
        age = Integer.parseInt(input.nextLine());
        System.out.println("Nhap dia chi sv");
        address = input.nextLine();
        System.out.println("Nhập email sinh vien");
        email = input.nextLine();
        System.out.println("Nhap phone sinh vien");
        phone = Integer.parseInt(input.nextLine());
    }

    public void display() {
        System.out.println(toString());
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BaiThi1;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Thien Phu
 */
public class Main {
 
    public static void main(String[] args) {
        Student st1 = new Student();
        Student st2 = new Student();
        st1.inputStudent();

        st2.inputStudent();

        st1.display();
        st2.display();
        if (st1.isCheckString()) {
            System.out.println("Student st1 có các thuộc tính chứa chuỗi = searching");
        } else {
            System.out.println("Student st1 không có các thuộc tính chứa chuỗi = searching");
        }
        System.out.println("");

        if (st2.isCheckString()) {
            System.out.println("Student st2 có các thuộc tính chứa chuỗi = searching");
        } else {
            System.out.println("Student st2 không có các thuộc tính chứa chuỗi = searching");
        }

    }
}



Thành Lâm [T1907A]
Thành Lâm

2020-05-11 07:44:45

Em Làm Đề 2. 

Câu 1.
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package t1907akt;

import java.util.Scanner;

/**
 *
 * @author Thannh Lam
 */
public class T1907AKT {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
         Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] arr = new int[n];
         
         for(int i = 0; i <n; i++){
             arr[i] = sc.nextInt();
         }
         
         for(int i =0; i <n; i++){
             for(int j =i+1; j<n;j++){
                 if(arr[i] > arr[j]){
                     int temp = arr[i];
                     arr[i] = arr[j];
                     arr[j] = temp;
                 }
             }
         }
         
         for(int i = 0; i <n; i++){
             System.out.print(arr[i] + " ");
         }
    }
    
}

Câu 2



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Baitap;

import java.util.Scanner;

/**
 *
 * @author Thannh Lam
 */
public class Person {
      String name;
      String gender;
      String birthday;
      String address;

    public Person() {
    }

    public Person(String name, String gender, String birthday, String address) {
        this.name = name;
        this.gender = gender;
        this.birthday = birthday;
        this.address = address;
    }
    
    public void inputInfo() {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập tên: ");
        name = input.nextLine();
        
        System.out.println("Nhập giới tính: ");
        gender = input.nextLine();
        
        System.out.println("Nhập ngày sinh: ");
        birthday = input.nextLine();
        
        System.out.println("Nhập địa chỉ: ");
        address = input.nextLine();
    }
    
    public void showInfo(){
        System.out.println("Tên: " + name + "; giới tính: " + gender+ ";ngày sinh: " +birthday+";địa chỉ: " + address);
        
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
      
      
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Baitap;

import java.util.Scanner;

/**
 *
 * @author Thannh Lam
 */
public class Student extends Person {
    String rollNo;
    float mark;
    String email;

    public Student() {
    }
    
    @Override
    public void inputInfo(){
        super.inputInfo();
        
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập mã sinh viên");
        //Code đầy đủ
        while(true){
            String rollNoInput = input.nextLine();
            boolean check = setRollNo(rollNoInput);
            if(check){
                break;  
            }
        }
        
        //Code ngắn gọn
       // while(!setRollNo(input.nextLine()));
        System.out.println("Nhập điểm sinh viên: ");
        while(true){
            float markInput = Float.parseFloat(input.nextLine());
            boolean check = setMark(markInput);
            if(check){
                break;  
            }
        }
        
        System.out.println("Nhập email sinh viên: ");
        while(true){
            String markEmail = input.nextLine();
            boolean check = setEmail(markEmail);
            if(check){
                break;  
            }
        }
    }
    
    
    public String getRollNo() {
        return rollNo;
    }

    public boolean setRollNo(String rollNo) {
        if(rollNo != null && rollNo.length() == 8 ){
            this.rollNo = rollNo;
            return true;
        }else{
            System.out.println("Nhập Lại Mã Sinh Viên ");
        }
        this.rollNo = rollNo;
        return false;
    }

    public float getMark() {
        return mark;
    }

    public boolean setMark(float mark) {
        if(mark >=0 && mark <=10) {
            this.mark = mark;
            return true;
        }else{
            System.err.println("Nhập lại điểm (điểm >=0 <=10) : ");
            return false;
        }
        
        
    }

    public String getEmail() {
        return email;
    }

    public boolean setEmail(String email) {
        if(email != null && email.contains("@") && !email.contains(" ")){
            this.email = email;
            return true;
        } else{
            System.out.println("Nhập lại đại chỉ email");
            return false;
        }
    }
    
    public boolean checkSchoolarship() {
        if(mark >=8) {
            return true;
        }
        return false;
    }
}



/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Baitap;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author Thannh Lam
 */
public class StudentTest {
    public static void main(String[] args) {
       ArrayList<Student> studentList = new ArrayList<>();
       int choose;
       Scanner scan = new Scanner(System.in);
       do{
           showMenu();
           System.out.println("Choose : ");
           choose = Integer.parseInt(scan.nextLine());
           
           switch(choose){
               case 1:
                   int n;
                   System.out.println("Nhập số sinh viên cần thêm: ");
                   n = Integer.parseInt(scan.nextLine());
                   for(int i = 0; i< n; i++){
                       Student std = new Student();
                       std.inputInfo();
                       
                       studentList.add(std);
                   }
                    break;
               case 2:
                   for(int i = 0; i < studentList.size();i++){
                       studentList.get(i).showInfo();
                   }
                  
                    break;
               case 3:
                   int minIndex = 0, maxIndex = 0;
                   float minMark, maxMark;
                   minMark = studentList.get(0).getMark();
                   maxMark = studentList.get(0).getMark();
                   
                   for(int i = 1; i<studentList.size(); i++){
                       if(studentList.get(i).getMark() < minMark){
                           minIndex = i;
                           minMark = studentList.get(i).getMark();
                       }
                       
                       if(studentList.get(i).getMark() > maxMark) {
                           maxIndex = i;
                           maxMark = studentList.get(i).getMark();
                       }
                   }
                   System.out.println("Sinh viên có điểm trung bình cao nhất.");
                   studentList.get(maxIndex).showInfo();
                   
                   System.out.println("Sinh Viên có điểm trung bình thấp nhất");
                   studentList.get(minIndex).showInfo();
                    break;
               case 4:
                   String rollNoSearch = scan.nextLine();
                   int count = 0;
                   System.out.println("Nhập rollNo cần tìm kiếm");
                   
                   for(Student student: studentList){
                       if(student.getRollNo().equalsIgnoreCase(rollNoSearch)){
                           student.showInfo();
                       }
                   }
                   if(count == 0){
                       System.out.println("Không tìm thấy sinh viên nào");
                   }
                    break;
               case 5:
                   //Buoc 1: Sắp xếp thông tin sinh viên theo A-Z 
                   
                   
                   System.out.println("");
                    break;
               case 6:
                   System.out.println("");
                    break;
               case 7:
                   System.out.println("GoodBye");
                    break;
               default:
                   System.err.println("Nhập sai:");
                   break;
           
           
           }
       }while(choose != 7);
    }
    
    static void showMenu(){
        System.out.println("1.Nhập vào N sinh viên");
        System.out.println("2. Hiển thị thông tin sinh viên");
        System.out.println("3.Hiển thị max và min theo điểm trung bình");
        System.out.println("4.Tìm kiếm theo mã sinh viên");
        System.out.println("5.Sort A-Z theo tên sinh viên và hiển thị");
        System.out.println("6. Hiển thị sinh viên được học bổng & sắp xếp điểm cao xuống thấp");
        
    }
    
}



Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó