Bài 4 – Chia hết, chia lấy dư
*Lí thuyết: một số kiểu biến trong Java
Bạn đã biết 2 kiểu String (chuỗi) và int (nguyên) bây giờ bạn biết thêm kiểu float (thực)
Số nguyên và số thực bạn biết sự khác nhau rồi chứ. Bây giờ ta bắt đầu bài toán ví dụ
import java.io.*;
public class Hello {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Nhap a: ");
float a = Float.parseFloat(in.readLine());
System.out.print("Nhap b: ");
float b = Float.parseFloat(in.readLine());
float ketqua = a/b;
System.out.println("Ket qua bai toan a+b la: " + ketqua);
}
} import java.io.*;
public class Hello {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Nhap a: ");
int a = Integer.parseInt(in.readLine());
System.out.print("Nhap b: ");
int b = Integer.parseInt(in.readLine());
float ketqua = a/b;
System.out.println("Ket qua bai toan a+b la: " + ketqua);
}
} import java.io.*;
public class Hello {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Nhap a: ");
int a = Integer.parseInt(in.readLine());
System.out.print("Nhap b: ");
int b = Integer.parseInt(in.readLine());
float ketqua = a%b;
System.out.println("Ket qua bai toan a+b la: " + ketqua);
}
}
hay mod
![]()
Copyright 2013 - 2015 Game cho Sky
Thiết kế bởi: Blogger Việt

