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).
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![lê văn phương [T1907A]](https://www.gravatar.com/avatar/a07ddfb51e1e7189c76b4e42dbdbcddc.jpg?s=80&d=mm&r=g)
lê văn phương
2020-05-11 08:13:42
package de2;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Main {
public static void main(String[] args) {
Student stdA = new Student();
Student stdB = new Student();
stdA.nhap();
stdB.nhap();
stu(stdB);
stu(stdA);
}
public static void stu( Student std) {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap chuooi can tim");
String a = scan.nextLine();
String b = std.toString();
if (a.contains(b) {
System.out.println(std.hienthi());
}
}
}
*
* 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 de2;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Student {
String ten, diachi, email;
int tuoi, sdt;
public Student() {
}
public Student(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 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;
}
public void nhap() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap thong tin sinh vien:");
System.out.print("Nhap ten: ");
ten = scan.nextLine();
System.out.print("Nhap tuoi: ");
tuoi = Integer.parseInt(scan.nextLine());
System.out.print("Nhap dia chi: ");
diachi = scan.nextLine();
System.out.print("Nhap email: ");
email = scan.nextLine();
System.out.print("Nhap so dien thoai: ");
sdt = Integer.parseInt(scan.nextLine());
}
public void hienthi() {
System.out.println(toString());
}
@Override
public String toString() {
return "Student{" +
"ten='" + ten + '\'' +
", diachi='" + diachi + '\'' +
", email='" + email + '\'' +
", tuoi=" + tuoi +
", 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 de1;
import java.util.Scanner;
/**
*
* @author HOME
*/
public class ISA {
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");
}
}
![Đường Thanh Bình [T1907A]](https://www.gravatar.com/avatar/c2ef7c316acb82467912bf5677b52a8b.jpg?s=80&d=mm&r=g)
Đường Thanh Bình
2020-05-11 08:12:38
/*
* 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 test2;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class main {
public static void main(String[] args) {
int N;
Scanner scan = new Scanner(System.in);
N = Integer.parseInt(scan.nextLine());
int[] intArray = new int[N];
int number = 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) {
number++;
}
}
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;
}
}
}
int m = 0;
int n = N - number;
for (int i = 0; i < N; i++) {
if (intArray[i] % 2 == 0) {
if (m < N - number) {
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");
}
}
![Phan Bạch Tùng Dương [T1907A]](https://www.gravatar.com/avatar/e74e3ec62fe3a191929e12eecbe01edf.jpg?s=80&d=mm&r=g)
Phan Bạch Tùng Dương
2020-05-11 08:12:05
/*
* 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 SapXep;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Main {
public static void main(String[] args) {
int n, c, d;
Scanner scanner = new Scanner(System.in);
do {
System.out.println("Nhập vào số phần tử của mảng: ");
n = scanner.nextInt();
} while (n <= 0);
int A[] = new int[n];
int ch[] = new int[n];
int le[] = new int[n];
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 + ": ");
A[i] = scanner.nextInt();
}
c = d = 0;
for (int i = 0; i < n; i++) {
if (A[i] % 2 == 0) {
ch[c] = A[i];
c++;
} else {
le[d] = A[i];
d++;
}
}
System.out.println("Mảng đã sắp xếp là: ");
for (int i = 0; i < c; i++) {
System.out.print(ch[i] + "\t");
}
for (int i = 0; i < d; i++) {
System.out.print(le[i] + "\t");
}
}
![Phạm Ngọc Minh [T1907A]](https://www.gravatar.com/avatar/9fa44938f36838ed4b4ac8e30e070c74.jpg?s=80&d=mm&r=g)
Phạm Ngọc Minh
2020-05-11 08:11:21
Pham Ngoc Minh
/*
* 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 t1907a;
import java.util.Scanner;
/**
*
* @author minhr
*/
public class T1907a {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int a ;
Scanner scan = new Scanner(System.in);
a = Integer.parseInt(scan.nextLine());
int[] intArray = new int[a] ;
int numberofodd = 0 ;
int[] intArray01 = new int[a];
for ( int i = 0 ; i < a ; 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 < a - 1 ; i++ )
{
for ( int j = 0 ; j < a - 1 - i ; j++ )
{
if( intArray[j] > intArray[j+1] )
{
int temp = intArray[j];
intArray[j] = intArray[j+1];
intArray[j+1] = temp;
}
}
}
int m = 0 ;
int n = a - numberofodd;
for ( int i = 0 ; i < a ; i++)
{
if (intArray[i]%2 == 0)
{
if ( m < a - numberofodd)
{
intArray01[m++] = intArray[i];
}
}
else
{
if ( n < a )
{
intArray01[n++] = intArray[i];
}
}
}
for ( int i = 0 ; i < a ; i++)
{
intArray[i] = intArray01[i];
System.out.println(intArray[i]);
}
System.out.println("END");
}
}
![Luong Dinh Dai [T1907A]](https://www.gravatar.com/avatar/ca08fa4090e1038e541197564747f93c.jpg?s=80&d=mm&r=g)
Luong Dinh Dai
2020-05-11 08:09:38
/*
* 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 thithuchanh;
import java.util.Scanner;
/**
*
* @author FATE STORE
*/
public class Cau1 {
public static void main(String[] args) {
System.out.println("Nhap so N: ");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
int[] t = new int[n];
for (int i = 0; i < t.length; i++) {
System.out.println("Nhap phan tu thu " + (i + 1));
t[i] = sc.nextInt();
sc.nextLine();
}
Cau1 c = new Cau1();
c.sapxep(t, n);
c.hienthi(t, n);
}
void sapxep(int t[], int n) {
int i, j;
for (i = 0; i < n - 1; i++) {
for (j = i + 1; j < n; j++) {
if ((t[i] % 2 != 0 && t[j] % 2 == 0)
|| (t[i] % 2 == 0 && t[j] % 2 == 0 && t[i] > t[j])
|| (t[i] % 2 != 0 && t[j] % 2 != 0 && t[i] > t[j])) {
int a = t[i];
t[i] = t[j];
t[j] = a;
}
}
}
}
void hienthi(int t[], int n) {
System.out.println("Mang sau khi sap xep: ");
for (int i = 0; i < t.length; i++) {
System.out.print(t[i] + " ");
}
}
}
/*
* 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 thithuchanh;
import java.util.Scanner;
/**
*
* @author FATE STORE
*/
public class SinhVien {
private String ten,tuoi,diachi,email,sdt;
public SinhVien() {
}
public SinhVien(String ten, String tuoi, String diachi, String email, String sdt) {
this.ten = ten;
this.tuoi = tuoi;
this.diachi = diachi;
this.email = email;
this.sdt = sdt;
}
public String getTen() {
return ten;
}
public String getTuoi() {
return tuoi;
}
public String getDiachi() {
return diachi;
}
public String getEmail() {
return email;
}
public String getSdt() {
return sdt;
}
public void setTen(String ten) {
this.ten = ten;
}
public void setTuoi(String tuoi) {
this.tuoi = tuoi;
}
public void setDiachi(String diachi) {
this.diachi = diachi;
}
public void setEmail(String email) {
this.email = email;
}
public void setSdt(String sdt) {
this.sdt = sdt;
}
@Override
public String toString() {
return "SinhVien{" + "ten=" + ten + ", tuoi=" + tuoi + ", diachi=" + diachi + ", email=" + email + ", sdt=" + sdt + '}';
}
void input(){
Scanner sc = new Scanner(System.in);
System.out.println("Nhap ten: ");
ten = sc.nextLine();
System.out.println("Nhap tuoi: ");
tuoi = sc.nextLine();
System.out.println("Nhap dia chi: ");
diachi = sc.nextLine();
System.out.println("Nhap email: ");
email = sc.nextLine();
System.out.println("nhap sdt: ");
sdt = sc.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 thithuchanh;
/**
*
* @author FATE STORE
*/
public class Main {
public static void main(String[] args) {
SinhVien sv1 = new SinhVien();
SinhVien sv2 = new SinhVien();
sv1.input();
if (check(sv1.toString())) {
System.out.println("searching");
} else {
System.out.println("searching ko co");
}
sv2.input();
if (check(sv2.toString())) {
System.out.println("searching");
} else {
System.out.println("searching ko co");
}
}
public static boolean check(String text) {
if (text.contains("searching")) {
return true;
}
return false;
}
}
![Trần Anh Quân [T1907A]](https://www.gravatar.com/avatar/7e3a8fe30cedd711f426fc59a9d48efc.jpg?s=80&d=mm&r=g)
Trần Anh Quân
2020-05-11 08:08:33
package de2;
import java.util.Scanner;
/**
*
* @author Anh Quan
*/
public class b1 {
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;
}
}
}
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");
}
}
![Đỗ Văn Huấn [T1907A]](https://www.gravatar.com/avatar/04c40301dd027839d265b3c3c9dc6e6b.jpg?s=80&d=mm&r=g)
Đỗ Văn Huấn
2020-05-11 08:07:39
bai1
/*
* 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 Mon_ISA;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Bai1 {
public static void main(String[] args) {
int n, a=0, b=0;
Scanner scan = new Scanner(System.in);
System.out.print("Nhap so n phan tu: ");
n = Integer.parseInt(scan.nextLine());
int[] t = new int[n];
int sochan[] = new int[n];
int sole[] = new int[n];
for (int i = 0; i < n; i++) {
System.out.print("Nhap phan tu thu " + (i + 1) + " : ");
t[i] = Integer.parseInt(scan.nextLine());
}
for (int i = 0; i < n; i++) {
if (t[i] % 2 == 0) {
sochan[a] = t[i];
a++;
} else {
sole[b] = t[i];
b++;
}
}
sapxep(sochan,a);
sapxep(sole,b);
System.out.print("Mang da sap xep la : ");
hienthi(sochan);
hienthi(sole);
}
public static void sapxep(int[] arr, int m) {
int c = arr[0];
for (int i = 0; i < m - 1; i++) {
for (int j = i + 1; j < m; j++) {
if (arr[i] > arr[j]) {
c = arr[j];
arr[j] = arr[i];
arr[i] = c;
}
}
}
}
// cach 2 là dung collection.sort
public static void hienthi(int[] arr) {
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
}
}
bai2 /*
* 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 Mon_ISA;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Student {
String ten, diachi, email;
int tuoi, sdt;
public Student() {
}
public Student(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 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;
}
public void nhap() {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap thong tin sinh vien:");
System.out.print("Nhap ten: ");
ten = scan.nextLine();
System.out.print("Nhap tuoi: ");
tuoi = Integer.parseInt(scan.nextLine());
System.out.print("Nhap dia chi: ");
diachi = scan.nextLine();
System.out.print("Nhap email: ");
email = scan.nextLine();
System.out.print("Nhap so dien thoai: ");
sdt = Integer.parseInt(scan.nextLine());
}
public void hienthi() {
System.out.println(toString());
}
@Override
public String toString() {
return "Student{" +
"ten='" + ten + '\'' +
", diachi='" + diachi + '\'' +
", email='" + email + '\'' +
", tuoi=" + tuoi +
", 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 Mon_ISA;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class Main {
public static void main(String[] args) {
Student stdA = new Student();
Student stdB = new Student();
stdA.nhap();
stdB.nhap();
stu(stdB);
stu(stdA);
}
public static void stu( Student std) {
Scanner scan = new Scanner(System.in);
System.out.println("Nhap chuooi can tim");
String a = scan.nextLine();
String b = std.toString();
if (a.contains(b) {
System.out.println(std.hienthi());
}
}
}
![Đỗ tuấn anh [T1907A]](https://www.gravatar.com/avatar/98f1e29922dc48dd5d41b8f6cbce24e0.jpg?s=80&d=mm&r=g)
Đỗ tuấn anh
2020-05-11 08:07:32
package Thi;
/**
*
* @author Admin
*/
public class ISA {
/**
* @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");
}
![Thành Lâm [T1907A]](https://www.gravatar.com/avatar/fb1b94f4caad069ee6e3f42ea2221b49.jpg?s=80&d=mm&r=g)
Thành Lâm
2020-05-11 08:04:22
Đề 1:Còn câu 2 thầy để hạn chốt 21h tối nay để em hoàn thành được chứ ?
![Trần Anh Quân [T1907A]](https://www.gravatar.com/avatar/7e3a8fe30cedd711f426fc59a9d48efc.jpg?s=80&d=mm&r=g)
Trần Anh Quân
2020-05-11 08:02:52
b1
package de2;
/**
*
* @author Anh Quan
*/
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");
}