By GokiSoft.com| 19:56 13/02/2023|
Java Basic

Java Basic- Overview - Tổng hợp bài tập ôn luyện java basic - Kiểm tra 60 phút

Bài 1: Tính tổng các số nguyên từ 0->N (N được nhập từ bàn phím)

Bài 2: Nhập vào mảng số nguyên gồm N phần tử (N được nhập từ bàn phím) -> In ra các số chia hết cho 2

Bài 3 : Tạo lớp đối tượng Book gồm các thuộc tính sau

- tên sách, tác giả, nhà sản xuất, năm sản xuất

-Viết getter/setter và 2 hàm tạo 

- Viết hàm nhập/hàm hiển thị

- Tạo 2 đối tượng Book với 2 hàm tạo tương ứng trong phương thức main của lớp test. Nhập và hiển thị thông tin sách

Bài 4 :

Tạo lớp People gồm các thuộc tính : tên, địa chỉ

- tạo hàm nhập và hiển thị thông tin sinh viên

Tạo lớp Student kế thừa từ lớp People và có thêm các thuộc tính rollNo

- Ghi đè 2 phương thức nhập và hiển thị thông tin sinh viên

Tạo 2 đối tượng People và Student trong phương thức main của lớp Test. Thực hiện nhập và hiển thị thông tin của 2 đối tượng trên.

Bài 5:

Tạo lớp Vehicle gồm 3 phương thức abstract : running, input, display

Tạo lớp Car kế thừa từ lớp Vehicle có thuộc tính name, số bánh xe.

- Viết các hàm input và display và running (hàm running sẽ hiển thị dòng Car is running)

Tạo lớp BikeCycle kế thừa từ lớp Vehicle có thuộc tính name, số bánh xe

- Viết các hàm input và display và running (hàm running sẽ hiển thị dòng BikeCycle is running)

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

5

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

Trần Anh Quân [T1907A]
Trần Anh Quân

2020-03-11 10:20:19

b2


package kt60p;

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

/**
 *
 * @author Anh Quan
 */
public class bt2 {
     public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Scanner scan = new Scanner(System.in);
        int n ;
        System.out.print("Nhập số lượng số nguyên nhập vào mảng: ");
        n= Integer.parseInt(scan.nextLine());
        for (int i = 0; i < n; i++) {
            int s = i+1;
            System.out.print("Số thứ"+s+" : " );
            int a;
            a= Integer.parseInt(scan.nextLine());
            list.add(a);
        }
        System.out.println("In ra các số chia hết cho 2 : ");
        for (int i = 0; i < list.size(); i++) {
            if ( list.get(i)%2 ==0) {
                System.out.println(" , "+list.get(i));
            }
        }
    }
}



Trần Anh Quân [T1907A]
Trần Anh Quân

2020-03-11 10:07:04

B1


package bttinhtong;

import java.util.Scanner;

/**
 *
 * @author Anh Quan
 */
public class Bttinhtong {

    /**
     * @param args the command line arguments
     */
       public static void main(String[] args) {
    int n, soDu, tong = 0;
    Scanner scanner = new Scanner(System.in);
         
    System.out.println("Nhập vào các số số nguyên dương bất kỳ: ");
    n = scanner.nextInt();
         
    while (n > 0) {
        soDu = n % 10;
        n = n / 10;
        tong += soDu;
    }
         
    System.out.println("Tổng các chữ số = " + tong);
}
}



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

2020-03-11 10:06: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 Bt997.Bai4;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class Student extends People {

    String rollNo;

    @Override
    public void input() {
        Scanner scan = new Scanner(System.in);
        System.out.println("Student Id : ");
        rollNo = scan.nextLine();
        System.out.println("Student name : ");
        name = scan.nextLine();
        System.out.println("Student address : ");
        address = scan.nextLine();
    }

    @Override
    public void display() {
        System.out.println(toString());
        super.display(); //To change body of generated methods, choose Tools | Templates.
        
    }

    @Override
    public String toString() {
        return "Student{" + "rollNo=" + rollNo + '}';
    }

}



/*
 * 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 Bt997.Bai4;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class People {
    String name , address;
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Name : ");
        name = scan.nextLine();
        System.out.println("Address : ");
        address = scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "People{" + "name=" + name + ", 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 Bt997.Bai4;

/**
 *
 * @author DELL
 */
public class main {
    public static void main(String[] args) {
        People P = new People();
        People s = new Student();
        P.input();
        P.display();
        s.input();
        s.display();
    }
}



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

2020-03-11 10:04:58



/*
 * 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 Bt997.Bai3;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class Book {
    String bookName , author , nhaXB,namXB;

    public Book() {
    }

    public Book(String bookName, String author, String nhaXB, String namXB) {
        this.bookName = bookName;
        this.author = author;
        this.nhaXB = nhaXB;
        this.namXB = namXB;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getNhaXB() {
        return nhaXB;
    }

    public void setNhaXB(String nhaXB) {
        this.nhaXB = nhaXB;
    }

    public String getNamXB() {
        return namXB;
    }

    public void setNamXB(String namXB) {
        this.namXB = namXB;
    }
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Book name : ");
        bookName = scan.nextLine();
        System.out.println("Author name : ");
        author = scan.nextLine();
        System.out.println("Nha san xuat : ");
        nhaXB = scan.nextLine();
        System.out.println("nam san xuat : ");
        namXB =  scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", author=" + author + ", nhaXB=" + nhaXB + ", namXB=" + namXB + '}';
    }
}



/*
 * 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 Bt997.Bai3;

/**
 *
 * @author DELL
 */
public class Main {
    public static void main(String[] args) {
        Book bk = new Book();
        Book bok;
        bok = new Book(bk.bookName, bk.author, bk.nhaXB, bk.namXB);
        bk.input();
        bk.display();
        bok.display();
    }
}



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

2020-03-11 10:04:54



/*
 * 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 Bt997.Bai3;

import java.util.Scanner;

/**
 *
 * @author DELL
 */
public class Book {
    String bookName , author , nhaXB,namXB;

    public Book() {
    }

    public Book(String bookName, String author, String nhaXB, String namXB) {
        this.bookName = bookName;
        this.author = author;
        this.nhaXB = nhaXB;
        this.namXB = namXB;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getNhaXB() {
        return nhaXB;
    }

    public void setNhaXB(String nhaXB) {
        this.nhaXB = nhaXB;
    }

    public String getNamXB() {
        return namXB;
    }

    public void setNamXB(String namXB) {
        this.namXB = namXB;
    }
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Book name : ");
        bookName = scan.nextLine();
        System.out.println("Author name : ");
        author = scan.nextLine();
        System.out.println("Nha san xuat : ");
        nhaXB = scan.nextLine();
        System.out.println("nam san xuat : ");
        namXB =  scan.nextLine();
    }
    public void display(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Book{" + "bookName=" + bookName + ", author=" + author + ", nhaXB=" + nhaXB + ", namXB=" + namXB + '}';
    }
}



/*
 * 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 Bt997.Bai3;

/**
 *
 * @author DELL
 */
public class Main {
    public static void main(String[] args) {
        Book bk = new Book();
        Book bok;
        bok = new Book(bk.bookName, bk.author, bk.nhaXB, bk.namXB);
        bk.input();
        bk.display();
        bok.display();
    }
}



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

2020-03-11 10:03:34



/*
 * 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 Bt997;
import java.util.ArrayList;
import java.util.Scanner;
/**
 *
 * @author DELL
 */
public class Bai1 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Scanner scan = new Scanner(System.in);
        int n ;
        System.out.println("Nhap so luong so nguyen can tinh : ");
        n= Integer.parseInt(scan.nextLine());
        for (int i = 0; i < n; i++) {
            int s = i+1;
            System.out.println("nhap so thu"+s+" : " );
            int a;
            a= Integer.parseInt(scan.nextLine());
            list.add(a);
        }
        n=0;
        for (int i = 0; i < list.size(); i++) {
            n+=list.get(i);
        }
        System.out.println("Tong cac so trong mang la : "+n);
    }
}



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

2020-03-11 10:02:57



/*
 * 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 Bt997;

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

/**
 *
 * @author DELL
 */
public class Bai2 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Scanner scan = new Scanner(System.in);
        int n ;
        System.out.println("Nhap so luong so nguyen trong mang : ");
        n= Integer.parseInt(scan.nextLine());
        for (int i = 0; i < n; i++) {
            int s = i+1;
            System.out.println("nhap so thu "+s+" : " );
            int a;
            a= Integer.parseInt(scan.nextLine());
            list.add(a);
        }
        System.out.println("In ra các số chia hết cho 2 : ");
        for (int i = 0; i < list.size(); i++) {
            if ( list.get(i)%2 ==0) {
                System.out.println(" , "+list.get(i));
            }
        }
    }
}



Phí Văn Long [T1907A]
Phí Văn Long

2020-03-11 10:02:17

bài 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author PhiNong
 */
public class Main {
    public static void main(String[] args) {
        float sum = 0 , number ;
        Scanner scanner = new Scanner(System.in);
        
    do {
        System.out.println("Nhap vao so :");
        number = scanner.nextFloat();
        sum += number;
        
        if(sum > 1000)
              break;
    }while(number >= 0);
        System.out.println("Tong = " + sum);
    }
}
bài 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author Nong
 */
public class bai2 {
    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        
        do{
            System.out.println("Nhap vao so phan tu của mảng: ");
            n = scanner.nextInt();
        }while (n <=0 );
        
        int A[] = 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.println("Nhập phần tử thứ" + i + ":");
            A[i] = scanner.nextInt();
        }
        System.out.println("Cac phần tử trong mảng chia hết cho 2 là : ");
        for (int i = 0; i < n; i++) {
            if (A[i] % 2 == 0){
                System.out.println(A[i] +"\t");
            }
        }
    }
}


Phí Văn Long [T1907A]
Phí Văn Long

2020-03-11 10:02:16

bài 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author PhiNong
 */
public class Main {
    public static void main(String[] args) {
        float sum = 0 , number ;
        Scanner scanner = new Scanner(System.in);
        
    do {
        System.out.println("Nhap vao so :");
        number = scanner.nextFloat();
        sum += number;
        
        if(sum > 1000)
              break;
    }while(number >= 0);
        System.out.println("Tong = " + sum);
    }
}
bài 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author Nong
 */
public class bai2 {
    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        
        do{
            System.out.println("Nhap vao so phan tu của mảng: ");
            n = scanner.nextInt();
        }while (n <=0 );
        
        int A[] = 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.println("Nhập phần tử thứ" + i + ":");
            A[i] = scanner.nextInt();
        }
        System.out.println("Cac phần tử trong mảng chia hết cho 2 là : ");
        for (int i = 0; i < n; i++) {
            if (A[i] % 2 == 0){
                System.out.println(A[i] +"\t");
            }
        }
    }
}


Phí Văn Long [T1907A]
Phí Văn Long

2020-03-11 10:02:16

bài 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author PhiNong
 */
public class Main {
    public static void main(String[] args) {
        float sum = 0 , number ;
        Scanner scanner = new Scanner(System.in);
        
    do {
        System.out.println("Nhap vao so :");
        number = scanner.nextFloat();
        sum += number;
        
        if(sum > 1000)
              break;
    }while(number >= 0);
        System.out.println("Tong = " + sum);
    }
}
bài 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 Bai1_javabasic;

import java.util.Scanner;

/**
 *
 * @author Nong
 */
public class bai2 {
    public static void main(String[] args) {
        int n;
        Scanner scanner = new Scanner(System.in);
        
        do{
            System.out.println("Nhap vao so phan tu của mảng: ");
            n = scanner.nextInt();
        }while (n <=0 );
        
        int A[] = 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.println("Nhập phần tử thứ" + i + ":");
            A[i] = scanner.nextInt();
        }
        System.out.println("Cac phần tử trong mảng chia hết cho 2 là : ");
        for (int i = 0; i < n; i++) {
            if (A[i] % 2 == 0){
                System.out.println(A[i] +"\t");
            }
        }
    }
}