Tổng hợp bài tập ôn luyện kiến thức java căn bản - java core
Bài 1:
In ra màn hình dòng chữ “Hello, this is my first appliation”.
Bài 2:
Nhập 1 số nguyên, 1 số double, 1 ký tự, 1 chuỗi từ bàn phím và hiển thị giá trị các biến vừa nhập ra màn hình.
Bài 3:
Tìm max, min của 2 (hoặc 3) số được nhập vào từ bàn phím
Bài 4:
Giải phương trình bậc nhất: ax + b = 0.
Bài 5:
Giải phương trình bậc 2: ax^2 + bx +c = 0.
Bài 6:
Nhập 1 số có tối đa 4 chữ số, in số đó ra dưới dạng chữ.
Bài 7:
Tính tổng từ 1 đến 100
Bài 8:
Tính tổng từ 1 đến n.
Bài 9:
Tìm ước chung lớn nhất, BCNN của 2 số được nhập vào từ bàn phím.
Bài 10:
Kiểm tra 1 số có là số nguyên tố hay không?
Bài 11:
In ra các số nguyên tố từ 1 đến n
Bài 12:
Kiểm tra 1 số hoàn hảo (là số có tổng các ước nhỏ hơn nó, bằng chính nó)
(Ex: 6 = 1+2+3).
Bài 13:
In ra các số hoàn hảo từ 1 đến n.
Bài 14:
In ra dãy fibonacy nằm trong giới hạn từ 1 đến n
( 1 2 3 5 8 13 …)
Bài 15:
Nhập vào 1 số n, in số đó ra dạng tích lũy thừa các thừa số nguyên tố.
Bài 16:
Nhập 1 mảng có 10 phần tử các số nguyên, hiển thị mảng vừa nhập ra màn hình.
Bài 17:
Nhập tự động (Dùng lớp Random) mảng có 10 phần tử các số nguyên, hiển thị mảng vừa nhập ra màn hình.
Bài 18:
Nhập mảng có n phần tử (bằng tay hoặc tự động) các số nguyên, hiển thị mảng vừa nhập ra màn hình.
Bài 19:
Nhập mảng có n phần tử các số nguyên, In ra phần tử max, min của mảng.
Bài 20
Nhập mảng có n phần tử các số nguyên, In ra các phần tử là số nguyên tố của mảng.
Bài 21:
Nhập mảng có n phần tử các số nguyên, In ra các phần tử là số hoản hảo của mảng.
Bài 22:
Nhập mảng có n phần tử các số nguyên, In ra các phần tử là số chẵn.
Bài 23:
Nhập mảng có n phần tử các số nguyên, Sắp xếp mảng tăng dần bằng thuật toán Chọn trực tiếp và hiển thị mảng đã sắp xếp ra màn hình.
Bài 24:
Nhập mảng có n phần tử các số nguyên, Sắp xếp mảng tăng dần bằng thuật toán Nổi bọt và hiển thị mảng đã sắp xếp ra màn hình.
Bài 25:
Nhập mảng có n phần tử các số nguyên, Sắp xếp mảng tăng dần bằng thuật toán Chèn và hiển thị mảng đã sắp xếp ra màn hình
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![vuong huu phu [T2008A]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2021-01-24 05:04:37
import java.util.Scanner;
/*
* 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.
*/
/**
*
* @author Admin
*/
public class bai_9 {
public static void main(String[] args) {
int a, b, ucln = 1, i;
Scanner scan = new Scanner(System.in);
System.out.println("Nhap gia tri cho so a = ");
a = scan.nextInt();
System.out.println("Nhap gia tri cho so b = ");
b = scan.nextInt();
if (a == b) {
System.out.println("Uoc chung lon nhat la: " + a);
}
for (i = 1; i < a && i < b; i++) {
if (a % i == 0 && b % i == 0) {
ucln = i;
}
}
System.out.println("Uoc chung lon nhat la: " + ucln);
int bcnn = (a*b)/ucln;
System.out.println("Uoc chung lon nhat la: " + bcnn
);
}
}
![vuong huu phu [T2008A]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2021-01-23 10:17:14
import java.util.Scanner;
/*
* 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.
*/
/**
*
* @author Admin
*/
public class bai_8 {
public static void main(String[] args) {
int n;
Scanner scan = new Scanner(System.in);
System.out.print(" nhap vao gia tri cua so n la : ");
n = scan.nextInt();
int i, tong = 0;
for (i = 0; i <=n; i++) {
tong = tong + i;
}
System.out.println("tong = "+ tong);
}
}
![vuong huu phu [T2008A]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2021-01-23 10:11:51
/*
* 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.
*/
/**
*
* @author Admin
*/
public class bai_7 {
public static void main(String[] args) {
int n = 100;
int i, tong = 0;
for (i = 0; i < n; i++) {
tong = tong + i;
}
System.out.println("tong = "+ tong);
}
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2021-01-22 10:04: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 newpackage;
import java.text.DecimalFormat;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class NewClass {
public static void main(String[] args) {
// Bai 4 :
int a, b;
double nghiem;
DecimalFormat decimalFormat = new DecimalFormat("#.##");
Scanner scanner = new Scanner(System.in);
System.out.println("Nhap a: ");
a = scanner.nextInt();
System.out.println("Nhap b: ");
b = scanner.nextInt();
System.out.println("Phuong trinh nhap vao la : " + a + "x + " + b + " = 0.");
if (a == 0) {
if (b == 0) {
System.out.println("Phuong trinh VSN");
} else {
System.out.println("Phuong trinh VN");
}
} else {
nghiem = (double) -b / a;
System.out.println("Phuong trinh co nghiem x = " + decimalFormat.format(nghiem) + ".");
}
}
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2021-01-22 09:42:28
/*
* 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 newpackage;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class NewClass {
public static void main(String[] args) {
// Bai 3 :
int numbers[] = new int [] {3, 6};
int min = numbers[0];
int max = numbers[0];
for(int i = 0; i < numbers.length; i++) {
if(numbers[i] < min) {
min = numbers[i];
}
if(numbers[i] > max) {
max = numbers[i];
}
}
System.out.println("max = " + max);
System.out.println("min = " + min);
}
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2021-01-22 09:33:39
/*
* 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 newpackage;
import java.util.Scanner;
/**
*
* @author Admin
*/
public class NewClass {
public static void main(String[] args) {
// Bai 2 :
Scanner scan = new Scanner (System.in);
int m;
char n;
double i;
String a;
System.out.println("Nhap so nguyen : ");
m = scan.nextInt();
System.out.println("Nhap ki tu : ");
n = scan.next().charAt(0);
scan.nextLine();
System.out.println("Nhap so double : ");
i = scan.nextDouble();
System.out.println("Nhap chuoi : ");
a = scan.nextLine();
System.out.println("m = " + m + "; n = " + n + "; i = " + i + "; a = " + a);
}
}
![Nguyễn Hữu Hiếu [T2008A]](https://www.gravatar.com/avatar/ca2884508b617fee77f000c7d99c219d.jpg?s=80&d=mm&r=g)
Nguyễn Hữu Hiếu
2021-01-22 08:47:50
/*
* 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 aptech;
import java.util.Scanner;
/**
*
* @author UserName
*/
public class Ex980 {
//Bai 16-17
public static void main(String[] args) {
int n;
System.out.println("Nhap n = ");
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
int[] list = new int[n];
for (int i = 0; i < n; i++) {
list[i] = (int) (Math.random() * 10);
}
System.out.println("Danh sach phan tu: ");
for (int i = 0; i < n; i++) {
System.out.println(list[i]);
}
}
}
![Nguyễn Hữu Hiếu [T2008A]](https://www.gravatar.com/avatar/ca2884508b617fee77f000c7d99c219d.jpg?s=80&d=mm&r=g)
Nguyễn Hữu Hiếu
2021-01-22 08:43:50
/*
* 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 aptech;
import java.util.Scanner;
/**
*
* @author UserName
*/
public class Ex980 {
//Bai 16-17
public static void main(String[] args) {
int n;
System.out.println("Nhap n = ");
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
int[] list = new int[n];
for (int i = 0; i < n; i++) {
list[i] = scan.nextInt();
}
System.out.println("Danh sach phan tu: ");
for (int i = 0; i < n; i++) {
System.out.println(list[i]);
}
}
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2021-01-22 08:42:44
/*
* 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 newpackage;
/**
*
* @author Admin
*/
public class NewClass {
public static void main(String[] args) {
// Bai 1 :
System.out.println("Hello, this is my first appliation");
}
}
![Nguyễn Hữu Hiếu [T2008A]](https://www.gravatar.com/avatar/ca2884508b617fee77f000c7d99c219d.jpg?s=80&d=mm&r=g)
Nguyễn Hữu Hiếu
2021-01-22 08:25:21
/*
* 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 aptech;
import java.util.Scanner;
import java.lang.Math;
/**
*
* @author UserName
*/
public class Ex980 {
//Bai 7 - 8
public static void main(String[] args) {
int n;
System.out.println("Nhap n");
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
int sum = 0;
for (int i = 1; i <= n; i++) {
sum += i;
}
System.out.println("Sum 1 - " + n + " = " + sum);
}
}