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)
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2021-01-21 07:38:16
public class Bai3 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int a,b,c;
Scanner scan = new Scanner(System.in);
System.out.println("Nhap so a =");
a = scan.nextInt();
System.out.println("Nhap so b =");
b = scan.nextInt();
System.out.println("Nhap so c =");
c = scan.nextInt();
//tim Max
if(a > b && a > c){
System.out.println("a la Max" +a);
}
else if(b > a && b > c){
System.out.println("b la Max" + b);
}
else{
System.out.println("c la Max" +c);
}
//tim Min
if(a < b && a < c){
System.out.println("a la Min" +a);
}
else if(b < a && b < c){
System.out.println("b la Min" + b);
}
else{
System.out.println("c la Min" +c);
}
}
}
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2021-01-21 07:37:27
B2
public class Bai2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int a;
float b;
String c;
String d;
Scanner scan = new Scanner(System.in);
System.out.println("Nhap a =");
a = scan.nextInt();
System.out.println("Nhap b =");
b = scan.nextFloat();
System.out.println("Nhap 1 ki tu :");
c = scan.nextLine();
System.out.println("Nhap 1 chuoi:");
d = scan.nextLine();
}
}
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2021-01-21 07:36:32
public class Bai1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Hello, this is my first appliation");
}
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2021-01-21 04:21:42
Bai 20
/*
* 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 lesson1;
import static java.lang.Math.sqrt;
import java.util.Scanner;
/**
*
* @author MyPC
*/
public class BaiTap {
private static boolean IntCheck(int n){
if( n <= 1 ) return false;
for( int i = 2 ; i <= sqrt(n) ; i++ ){
if( n % i == 0 ) return false;
}
return true;
}
public static void main(String[] args) {
int n;
int []a;
Scanner scan = new Scanner(System.in);
n = scan.nextInt();
a = new int[n];
for( int i = 0 ; i < n ; i++ ){
a[i] = scan.nextInt();
}
for( int i = 0 ; i < n ; i++ ){
if( IntCheck( a[i] ) ) System.out.println( a[i] );
}
}
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2021-01-21 04:08:15
Bai 10
/*
* 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 lesson1;
import static java.lang.Math.sqrt;
import java.util.Scanner;
/**
*
* @author MyPC
*/
public class BaiTap {
public static void main(String[] args) {
int a;
int check = 0;
Scanner scan = new Scanner(System.in);
a = scan.nextInt();
if( a <=1 ){
System.out.println("Khong phai la so nguyen to");
return;
}
for( int i = 2 ; i <= sqrt(a) ; i++ ){
if( a % i == 0 ){
check = 1;
System.out.println("Khong phai la so nguyen to");
break;
}
}
if( check == 0 ) System.out.println("La so nguyen to");
}
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2021-01-21 03:58:54
Bai 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 lesson1;
import java.util.Scanner;
/**
*
* @author MyPC
*/
public class BaiTap {
public static void main(String[] args) {
int a;
double b;
char c;
String d;
Scanner scan = new Scanner(System.in);
a = scan.nextInt();
b = scan.nextDouble();
c = scan.next().charAt(0);
scan.nextLine();
d = scan.nextLine();
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
}
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2021-01-21 03:45:29
/*
* 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 lesson1;
import java.util.Scanner;
/**
*
* @author MyPC
*/
public class BaiTap {
public static void main(String[] args) {
System.out.println("Hello, this is my first appliation");
}
}
![Lê Xuân Dũng [JavaFree]](https://www.gravatar.com/avatar/af3e93d6e9bd94db12e2b8a1069aef68.jpg?s=80&d=mm&r=g)
Lê Xuân Dũng
2020-03-20 00:43:26
//Bai 02:
package nhap_hien_thi_co_ban;
import java.util.Scanner;
public class Nhap_Hien_thi_co_ban {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Nhap vao 1 so kieu nguyen: ");
int a = Integer.parseInt(sc.nextLine());
System.out.println("So nguyen la: "+a);
System.out.println("Nhap vao 1 so kieu double: ");
double d = sc.nextDouble();
System.out.println("So double la: "+d);
System.out.println("Nhap vao 1 ky tu char: ");
char c = sc.next().charAt(0);
System.out.println("1 ky tu char la: "+c);
sc.nextLine();
System.out.println("Nhap vao 1 chuoi: ");
String s = sc.nextLine();
System.out.println("1 chuoi la: "+s);
}
}
![Lê Xuân Dũng [JavaFree]](https://www.gravatar.com/avatar/af3e93d6e9bd94db12e2b8a1069aef68.jpg?s=80&d=mm&r=g)
Lê Xuân Dũng
2020-03-19 15:13:00
//Bài 4:
package giai_pt_bac_1;
import java.util.Scanner;
public class Giai_PT_bac_1 {
public static void main(String[] args) {
float a, b;
float x;
Scanner sc = new Scanner(System.in);
System.out.println("Nhap a:");
a = sc.nextFloat();
System.out.println("Nhap b:");
b = sc.nextFloat();
if(a==0)
if(b==0){
System.out.println("PT co vo so nghiem");
}
else{
System.out.println("PT vo nghiem");
}
else {
x= -b/a;
System.out.println("PT co nghiem duy nhat x = "+x);
}
}
}
![Lê Xuân Dũng [JavaFree]](https://www.gravatar.com/avatar/af3e93d6e9bd94db12e2b8a1069aef68.jpg?s=80&d=mm&r=g)
Lê Xuân Dũng
2020-03-19 14:59:27
//Bài 3:
package tim_max_min_2_so;
import java.util.Scanner;
public class Tim_Max_Min_2_so {
public static void main(String[] args) {
int a, b, max, min;
Scanner sc = new Scanner(System.in);
System.out.println("Nhap so a = ");
a = Integer.parseInt(sc.nextLine());
System.out.println("Nhap so b = ");
b = Integer.parseInt(sc.nextLine());
if (a<b){
System.out.println("So lon nhat la: "+b);
System.out.println("So be nhat la: "+a);
}
else if(a>b){
System.out.println("So lon nhat la: "+a);
System.out.println("So be nhat la: "+b);
}
else {
System.out.println("Hai so a va b nhau nhau nen max = min = "+a);
}
}
}