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)

Hoàng Quang Huy [C1907L]
Hoàng Quang Huy

2020-04-01 13:11:44



//Bài 1
package Lesson1_4_2020;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập n: ");
        int n = Integer.parseInt(input.nextLine());
        int sum = 0;
        for (int i = 0; i <= n; i++) {
            sum += i;
        }
        System.out.println("Tổng từ 0 đến " + n + " là: " + sum);

//Bài 2
        System.out.println("Nhập N: ");
        int n1 = Integer.parseInt(input.nextLine());
        int[] arr = new int[n1];
        for (int i = 0; i < n1; i++) {
            System.out.println("Nhập phần tử thứ " + (i + 1));
            arr[i] = input.nextInt();
        }
        System.out.println("Các phần tử chia hết cho 2 là: ");
        for (int i = 0; i < n1; i++) {
            if (arr[i] % 2 == 0) {
                System.out.print(arr[i] + " ");
            }
        }
    }
}
-------------------------------------------------------------------------------------
//Bài 3
package Lesson4;
import java.util.*;

public class Book {

    private String bookName;
    private String bookAuthor;
    private String producer;
    private int yearPublishing;
    private float price;
    
    public Book(){}
    
    public Book(String bookName, String bookAuthor, String producer, int yearPublishing, float price) {
        this.bookName = bookName;
        this.bookAuthor = bookAuthor;
        this.producer = producer;
        this.yearPublishing = yearPublishing;
        this.price = price;
    }

    public String getBookName() {
        return bookName;
    }

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

    public String getBookAuthor() {
        return bookAuthor;
    }

    public void setBookAuthor(String bookAuthor) {
        this.bookAuthor = bookAuthor;
    }

    public String getProducer() {
        return producer;
    }

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public int getYearPublishing() {
        return yearPublishing;
    }

    public void setYearPublishing(int yearPublishing) {
        this.yearPublishing = yearPublishing;
    }

    public float getPrice() {
        return price;
    }

    public void setPrice(float price) {
        this.price = price;
    }
    // Hàm nhập
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.println("Nhập tên sách: ");
        bookName = input.nextLine();
        System.out.println("Nhập tên tác giả: ");
        bookAuthor = input.nextLine();
        System.out.println("Nhập tên nhà sản xuất: ");
        producer = input.nextLine();
        System.out.println("Nhập năm xuất bản: ");
        yearPublishing = Integer.parseInt(input.nextLine());
        System.out.println("Nhập giá tiền: ");
        price = Float.parseFloat(input.nextLine());
    }
    
    //Hàm xuất
    public void display(){
        System.out.println("Tên sách: "+bookName);
        System.out.println("Tên tác giả: "+bookAuthor);
        System.out.println("Tên nhà xuất bản: "+producer);
        System.out.println("Năm xuất bản: "+yearPublishing);
        System.out.println("Giá tiền: "+price);
    }
}
-------------------------------------------------------------------------------------
//Bài 4
package Lesson1_4_2020;

import java.util.Scanner;

public class People {
    private String name;
    private String address;
    
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.println("Input Name: ");
        name = input.nextLine();
        System.out.println("Input Address: ");
        address = input.nextLine();
    }

    @Override
    public String toString() {
        return "People{" + "name=" + name + ", address=" + address + '}';
    }
    
    public void output(){
        System.out.println(toString());
    }
}
---------------------------------------------------------------------------
//Class Student
package Lesson1_4_2020;

import java.util.Scanner;

public class Student extends People {

    private String rollNo;

    @Override
    public void input() {
        super.input();
        Scanner input = new Scanner(System.in);
        System.out.println("Input rollNo: ");
        rollNo = input.nextLine();
    }

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

    @Override
    public void output() {
        System.out.println(toString());
    }

}
-------------------------------------------------------------------------------------
// Test Bài 3 Bài 4
package Lesson1_4_2020;

public class Test {
    public static void main(String[] args) {
        Book book1 = new Book();
        Book book2 = new Book("Book 2","Author 2","Producer 2",2000);
        book1.input();
        book1.output();
        book2.output();

        People people1 = new People();
        People std1 = new Student();
        
        people1.input();
        std1.input();
        people1.output();
        std1.output();

    }
}
-------------------------------------------------------------------------------------
//Bài 5
package Lesson1_4_2020;

public abstract class Vehicle {
    public abstract void running();
    public abstract void input();
    public abstract void display();
    
}
-------------------------------------------------------------------------------------
package Lesson1_4_2020;

import java.util.Scanner;
public class Car extends Vehicle {

    private String name;
    private int numberOfWheel;

    @Override
    public void running() {
        System.out.println("Car is running");
    }

    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Input Car Name: ");
        this.name = input.nextLine();
        System.out.println("Innput Number of Wheel");
        this.numberOfWheel = Integer.parseInt(input.nextLine());
    }

    @Override
    public void display() {
        System.out.println("Car name: " + name);
        System.out.println("Number of wheel:" + numberOfWheel);
    }

}
-------------------------------------------------------------------------------------
package Lesson1_4_2020;

import java.util.Scanner;
public class Bicycle extends Vehicle{
    
    
    private String name;
    private int numberOfWheel;

    @Override
    public void running() {
        System.out.println("Bicycle is running");
    }

    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("Input Bicycle Name: ");
        this.name = input.nextLine();
        System.out.println("Innput Number of Wheel");
        this.numberOfWheel = Integer.parseInt(input.nextLine());
    }

    @Override
    public void display() {
        System.out.println("Bicycle name: " + name);
        System.out.println("Number of wheel:" + numberOfWheel);
    }
    
}



trung [C1907L]
trung

2020-04-01 13:08:44



package Buoi10;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Main {
    public static void main(String[] args) {
        //Tính tổng các số nguyên từ 0->N (N được nhập từ bàn phím)
        Scanner input = new Scanner(System.in);
        System.out.println("Nhap vao so n");
        int n = Integer.parseInt(input.nextLine());
        int tong = 0;
        for (int i = 0; i < n; i++) {
            tong += i;
        }
        System.out.format("tong la: %d",tong);
        
        //Nhap vao so nguyen n phan tu in ra cac so chia het 2
        System.out.println("Nhap vao so n");
        n = Integer.parseInt(input.nextLine());
        System.out.println("Cac so nguyen chia het cho 2 la:");
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                System.out.println(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 Buoi10;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Book {
    String tenSach,tacGia,nhaSanXuat;
    int namSanXuat;

    public Book() {
    }

    public Book(String tenSach, String tacGia, String nhaSanXuat, int namSanXuat) {
        this.tenSach = tenSach;
        this.tacGia = tacGia;
        this.nhaSanXuat = nhaSanXuat;
        this.namSanXuat = namSanXuat;
    }

    public String getTenSach() {
        return tenSach;
    }

    public String getTacGia() {
        return tacGia;
    }

    public String getNhaSanXuat() {
        return nhaSanXuat;
    }

    public int getNamSanXuat() {
        return namSanXuat;
    }

    public void setTenSach(String tenSach) {
        this.tenSach = tenSach;
    }

    public void setTacGia(String tacGia) {
        this.tacGia = tacGia;
    }

    public void setNhaSanXuat(String nhaSanXuat) {
        this.nhaSanXuat = nhaSanXuat;
    }

    public void setNamSanXuat(int namSanXuat) {
        this.namSanXuat = namSanXuat;
    }
    
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("ten sach: ?");
        tenSach = input.nextLine();
        System.out.println("tac gia: ?");
        tacGia = input.nextLine();
        System.out.println("nha san xuat: ?");
        nhaSanXuat = input.nextLine();
        System.out.println("nam san xuat: ?");
        namSanXuat = Integer.parseInt(input.nextLine());
    }

    @Override
    public String toString() {
        return "Book{" + "tenSach=" + tenSach + ", tacGia=" + tacGia + ", nhaSanXuat=" + nhaSanXuat + ", namSanXuat=" + namSanXuat + '}';
    }
    
    public void output() {
        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 Buoi10;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Main {
    public static void main(String[] args) {
        Book book1 = new Book();
        Book book2 = new Book("Cuon theo chieu gio","Nam cao","Kim Dong",1990);
        book1.input();
        book1.output();
        book2.output();
    }
}



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

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Student extends People{
    String rollNo;
    
    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        super.input();
        System.out.println("roll number: ?");
        rollNo = input.nextLine();
    }

    @Override
    public String toString() {
        return "Student{" + "ten=" + ten + ", diaChi=" + diaChi + ", rollNo=" + rollNo + '}';
    }
    
    @Override
    public void output() {
        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 Buoi10;

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Main {
    public static void main(String[] args) {
        People p1 = new People();
        Student s1 = new Student();
        p1.input();
        s1.input();
        p1.output();
        s1.output();
    }
}



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

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class BikeCycle extends Vehicle{

    @Override
    public void running() {
        System.out.println("BikeCycle is running");
    }

    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("name: ?");
        name = input.nextLine();
        System.out.println("so banh xe: ?");
        SoBanhXe = Integer.parseInt(input.nextLine());
    }

    @Override
    public void display() {
        System.out.format("name: %s",name);
        System.out.format("so banh xe: %d",SoBanhXe);
    }
    
}



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

import java.util.Scanner;

/**
 *
 * @author prdox
 */
public class Car extends Vehicle{

    @Override
    public void running() {
        System.out.println("Car is running");
    }

    @Override
    public void input() {
        Scanner input = new Scanner(System.in);
        System.out.println("name: ?");
        name = input.nextLine();
        System.out.println("so banh xe: ?");
        SoBanhXe = Integer.parseInt(input.nextLine());
    }

    @Override
    public void display() {
        System.out.format("name: %s",name);
        System.out.format("so banh xe: %d",SoBanhXe);
    }
    
    
    
}



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

/**
 *
 * @author prdox
 */
public abstract class Vehicle {
    String name;
    int SoBanhXe;

    public Vehicle() {
    }

    public Vehicle(String name, int SoBanhXe) {
        this.name = name;
        this.SoBanhXe = SoBanhXe;
    }
    
    public abstract void running();
    public abstract void input();
    public abstract void display();

    public String getName() {
        return name;
    }

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

    public int getSoBanhXe() {
        return SoBanhXe;
    }

    public void setSoBanhXe(int SoBanhXe) {
        this.SoBanhXe = SoBanhXe;
    }
}



Nguyễn Hoàng Anh [C1907L]
Nguyễn Hoàng Anh

2020-04-01 13:08:32



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

/**
 *
 * @author Redmibook 14
 */
public class Book {

    public String name, author, producer;
    public int year;

    public String getName() {
        return name;
    }

    public String getAuthor() {
        return author;
    }

    public String getProducer() {
        return producer;
    }

    public int getYear() {
        return year;
    }

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

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

    public void setProducer(String producer) {
        this.producer = producer;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public Book(String name, String author, String producer, int year) {
        this.name = name;
        this.author = author;
        this.producer = producer;
        this.year = year;
    }

    void input(String name, String author, String producer, int year) {
        this.name = name;
        this.author = author;
        this.producer = producer;
        this.year = year;
    }

    void display() {
        System.out.println("Name : " + name);
        System.out.println("author : " + author);
        System.out.println("producer : " + producer);
        System.out.println("year : " + year);
    }
}



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

import java.util.*;

/**
 *
 * @author Redmibook 14
 */
public class Test {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Book book;
        ArrayList<Book> arrBook = new ArrayList();
        for (int i = 0; i < 2; i++) {
            System.out.println("Nhap ten sach");
            String name = input.nextLine();
            System.out.println("Nhap ten tac gia");
            String author = input.nextLine();
            System.out.println("Nhap ten nha san xuat");
            String producer = input.nextLine();
            System.out.println("Nhap nam san xuat");
            int year = Integer.parseInt(input.nextLine());
            book = new Book(name, author, producer, year);
            arrBook.add(book);
        }
        for (int i = 0; i < 2; i++) {
            arrBook.get(i).display();
        }
    }
}



hoangkhiem [C1907L]
hoangkhiem

2020-04-01 13:08:05



package Test2;

import java.util.Scanner;

/**
 *
 * @author Admin
 */
public class Arr {
    public static void main(String[] args) {
        
    
    Scanner nhap = new Scanner(System.in);
      int arr[] = new int[10];
       int tong = 0;
       for (int i = 0; i < arr.length; i++) {
           System.out.format("Arr[%d]:= ", i + 1);
           arr[i] = Integer.parseInt(nhap.nextLine());
           tong += arr[i];
       }
        System.out.format("Tong cac phan tu trong mang la: %d", tong);
}
}



/*
 * 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 Admin
 */
public class Arr2 {
    public static void main(String[] args) {
        
    Scanner nhap = new Scanner(System.in);
      int N;
      System.out.println("Nhap phan tu N");
      N = Integer.parseInt(nhap.nextLine());
      int arr[] = new int[N];
       int tong = 0;
      for (int i = 0; i < arr.length; i++) {
           System.out.format("arr[%d]= ", i + 1);
           arr[i] = Integer.parseInt(nhap.nextLine());
       }
       for (int i = 0; i < N; i++) {
               if (arr[i] % 2 == 0) {
                   tong += arr[i];
               }}
         System.out.println("Tổng các sổ chia hết cho 2 là: "+tong);
}
}



Ngô Quang Huy [C1907L]
Ngô Quang Huy

2020-04-01 13:06:23



package April1;

import java.util.Scanner;

public class Bai1 {
    public static void main(String[] args) {
        Scanner input = new Scanner((System.in));
        System.out.print("Insert N = ");
        int tong=0;
        int n= Integer.parseInt(input.nextLine());
        for(int i=0;i<=n;i++){
            tong = tong + i;
        }
        System.out.println("Sum from 0 to "+n+" is: "+tong);
    }
}



package April1;

import java.util.Scanner;

public class Bai2 {
    public static void main(String[] args) {
        Scanner input = new Scanner((System.in));
        System.out.print("Insert N = ");
        int n= Integer.parseInt(input.nextLine());
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            System.out.println("Mang so "+i+": ");
            arr[i] = Integer.parseInt(input.nextLine());
        }
        System.out.print("so chia het cho 2: ");
        for(int i=0;i<n;i++){
            if(arr[i]%2==0){
                System.out.print(arr[i]+" ");
            }
        }
    }
}



package April1;

import java.util.Scanner;

public class Bai3Book {
    String Book;
    String Author;
    int year;

    public Bai3Book() {
    }

    public Bai3Book(String Book, String Author, int year) {
        this.Book = Book;
        this.Author = Author;
        this.year = year;
    }

    public String getBook() {
        return Book;
    }

    public void setBook(String Book) {
        this.Book = Book;
    }

    public String getAuthor() {
        return Author;
    }

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

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }
    
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.print("Insert Book: ");
        Book = input.nextLine();
        System.out.print("Insert Author: ");
        Author = input.nextLine();
        System.out.print("Insert Year: ");
        year = Integer.parseInt(input.nextLine());
    }
    
    public void output(){
        System.out.println("\nBook is "+Book);
        System.out.println("Author is "+Author);
        System.out.println("Year is "+year);
    }
}



package April1;

public class Bai3Main {
    public static void main(String[] args) {
        Bai3Book sach1 = new Bai3Book();
        Bai3Book sach2 = new Bai3Book("Batman","Tom King",2015);
        sach1.input();
        sach1.output();
        sach2.output();
    }
}



package April1;

import java.util.Scanner;

public class Bai4People {
    String Name;
    String Address;

    public Bai4People() {
    }

    public Bai4People(String Name, String Address) {
        this.Name = Name;
        this.Address = Address;
    }

    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 void input(){
        Scanner input = new Scanner(System.in);
        System.out.print("Insert Name: ");
        Name=input.nextLine();
        System.out.print("Insert Address: ");
        Address=input.nextLine();
    }
    
    public void output(){
        System.out.println("Name is: "+Name);
        System.out.println("Address is: "+Address);
    }
}



package April1;

import java.util.Scanner;

public class Bai4Student extends Bai4People{
    String Rollnumber;

    public Bai4Student() {
    }

    public Bai4Student(String Rollnumber) {
        this.Rollnumber = Rollnumber;
    }

    public Bai4Student(String Rollnumber, String Name, String Address) {
        super(Name, Address);
        this.Rollnumber = Rollnumber;
    }

    @Override
    public void input() {
        super.input();
        Scanner input = new Scanner(System.in);
        System.out.print("Insert Rollnumber: ");
        Rollnumber=input.nextLine();
    }

    @Override
    public void output() {
        super.output();
        System.out.println("Rollnumber is: "+ Rollnumber);
    }
    
    
}



package April1;

public class Bai4Test {
    public static void main(String[] args) {
        Bai4People num1 = new Bai4People();
        Bai4Student num2 = new Bai4Student();
        System.out.println("\nInsert People:");
        num1.input();
        System.out.println("\nInsert Student:");
        num2.input();
        System.out.println("\nPeople Info:");
        num1.output();
        System.out.println("\nStudent Info:");
        num2.output();
    }
}



package April1;

import java.util.Scanner;

public abstract class Bai5Vehicle {
    String Name;
    int Wheel;

    public Bai5Vehicle(String Name, int Wheel) {
        this.Name = Name;
        this.Wheel = Wheel;
    }

    public Bai5Vehicle() {
    }

    public String getName() {
        return Name;
    }

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

    public int getWheel() {
        return Wheel;
    }

    public void setWheel(int Wheel) {
        this.Wheel = Wheel;
    }
    
    abstract void running();
    public void input(){
        Scanner input = new Scanner(System.in);
        System.out.print("Insert Name: ");
        Name=input.nextLine();
        System.out.print("Insert Wheel: ");
        Wheel=Integer.parseInt(input.nextLine());
    }
    public void display(){
        System.out.println("Car Name is: "+Name);
        System.out.println("Car number of Wheel is: "+Wheel);
    }
}



package April1;


public class Bai5Car extends Bai5Vehicle{
    @Override
    void running() {
        System.out.println("Car is Running");
    }
    
    
}



package April1;


public class Bai5BikeCycle extends Bai5Vehicle{
    @Override
    void running() {
        System.out.println("BikeCycle  is Running");
    }
}



package April1;

public class Bai5Test {
    public static void main(String[] args) {
        Bai5Car car = new Bai5Car();
        car.input();
        car.display();
        car.running();
        
        Bai5BikeCycle bike = new Bai5BikeCycle();
        bike.input();
        bike.display();
        bike.running();
        
    }
}



Đinh Vũ Anh [C1907L]
Đinh Vũ Anh

2020-04-01 13:04:05



package btap;
import java.util.Scanner;
/**
 *
 * @author Admin
 */
public class Bai1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t = 0;
        System.out.print("Nhập vào số n: ");
        int n = Integer.parseInt(scan.nextLine());
        for(int i = 1; i <= n; i++){
            t += i;
        }
        System.out.println("Tổng các số nguyên từ 0 đến " + n + " là: " + t );
    }
}



Lê Trí Dũng [C1907L]
Lê Trí Dũng

2020-04-01 12:58:07



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

import java.util.Scanner;

/**
 *
 * @author Dzung
 */

public class bai2 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.print("Input n:");
        int n = Integer.parseInt(scan.nextLine());
        int[] t = new int[n];
        for (int i = 0; i < n; i++){
            System.out.print("Input the order number " + (i+1) + ":" );
            t[i] = Integer.parseInt(scan.nextLine());
        }
        System.out.print("Cac so chia het cho 2 la: " ); 
        for (int i = 0; i < n; i++){
          if (t[i] % 2 == 0)
              System.out.print(t[i] + " ");
        }
    } 
}



Lê Trí Dũng [C1907L]
Lê Trí Dũng

2020-04-01 12:57:33



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

/**
 *
 * @author Dzung
 */

import java.util.Scanner;
public class bai1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int sum = 0;
        System.out.print("Input n:");
        int n = Integer.parseInt(scan.nextLine());
        for (int i = 1; i <= n; i++){
            sum += i;
        }
        System.out.println("Sum of the numbers " + n + " = " + sum);   
    } 
}



Nguyễn Hoàng Anh [C1907L]
Nguyễn Hoàng Anh

2020-04-01 12:57:27



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

import java.util.*;

/**
 *
 * @author Redmibook 14
 */
public class SumPrime {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("Input n : ");

        int n = input.nextInt();
        int sum = 0;
        int sum2 = 0;
        for (int i = 2; i < n; i++) {
            int flag = 0;
            for (int j = 2; j < i; j++) {
                if (i % j == 0) {
                    flag++;
                }
            }
            if (flag == 0) {
                System.out.println(i);
                sum += i;
            }
        }
        System.out.println("Tong so nguyen to tu 1 - n la : " + sum);
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                System.out.println(i);
                sum2 += i;
            }
        }
        System.out.println("Tong so  tu 1 - n chia het cho 2 la : " + sum2);
    }
}



Vũ Việt Đức [C1907L]
Vũ Việt Đức

2020-04-01 12:51:23



/*
 * 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 lession8.bai3;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Book {
    String tenSach, tenTacGia, nhaXuatBan;
    int namSanXuat;

    public String getTenSach() {
        return tenSach;
    }

    public void setTenSach(String tenSach) {
        this.tenSach = tenSach;
    }

    public String getTenTacGia() {
        return tenTacGia;
    }

    public void setTenTacGia(String tenTacGia) {
        this.tenTacGia = tenTacGia;
    }

    public String getNhaXuatBan() {
        return nhaXuatBan;
    }

    public void setNhaXuatBan(String nhaXuatBan) {
        this.nhaXuatBan = nhaXuatBan;
    }

    public int getNamSanXuat() {
        return namSanXuat;
    }

    public void setNamSanXuat(int namSanXuat) {
        this.namSanXuat = namSanXuat;
    }

    public Book() {
    }

    public Book(String tenSach, String tenTacGia, String nhaXuatBan, int namSanXuat) {
        this.tenSach = tenSach;
        this.tenTacGia = tenTacGia;
        this.nhaXuatBan = nhaXuatBan;
        this.namSanXuat = namSanXuat;
    }
    
    public void show(){
        System.out.println(toString());
    }

    @Override
    public String toString() {
        return "Book{" + "tenSach=" + tenSach + ", tenTacGia=" + tenTacGia + ", nhaXuatBan=" + nhaXuatBan + ", namSanXuat=" + namSanXuat + '}';
    }
    
    public void input(){
        Scanner scanner = new Scanner(System.in);
        System.out.print("Nhập tên sách: ");
        tenSach = scanner.nextLine();
        System.out.print("Nhập tên tác giả: ");
        tenTacGia = scanner.nextLine();
        System.out.print("Nhập nhà xuất bản: ");
        nhaXuatBan = scanner.nextLine();
        System.out.print("Nhập năm sản xuất: ");
        namSanXuat = Integer.parseInt(scanner.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 lession8.bai3;

/**
 *
 * @author ADMIN
 */
public class Test {
    public static void main(String[] args){
        Book book1 = new Book();
        Book book2 = new Book("Sách hay", "Không biết", "Không biết", 1999);
        
        System.out.println("Nhập thông tin cho sách: ");
        book1.input();
        
        System.out.println("Thông tin sách: ");
        book1.show();
        book2.show();
    }
}