Trong các số tự nhiên từ 1 tới 100, hãy đếm xem có bao nhiêu số *- Chia hết cho 5. *- Chia 5 dư 1. *- Chia 5 du 2. *- Chia 5 dư 3. |
Java Source - Mã Java:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package z.test;
/**
*
* @author bnson
* @website vnlives.net
* @create 03/12/2014
*/
public class countDivided {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int du_0 = 0;
int du_1 = 0;
int du_2 = 0;
int du_3 = 0;
int i;
int soDu;
for (i = 1; i <= 100; i++) {
//System.out.println(i + " % 5 = " + i%5);
switch (soDu = i % 5) {
case 0:
du_0++;
break;
case 1:
du_1++;
break;
case 2:
du_2++;
break;
case 3:
du_3++;
break;
}
}
System.out.println("so cac so chia het cho 5 la: " + du_0);
System.out.println("So cac so chia 5 du 1 la: " + du_1);
System.out.println("So cac so chia 5 du 2 la: " + du_2);
System.out.println("So cac so chia 5 du 3 la: " + du_3);
}
}
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package z.test;
/**
*
* @author bnson
* @website vnlives.net
* @create 03/12/2014
*/
public class countDivided {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int du_0 = 0;
int du_1 = 0;
int du_2 = 0;
int du_3 = 0;
int i;
int soDu;
for (i = 1; i <= 100; i++) {
//System.out.println(i + " % 5 = " + i%5);
switch (soDu = i % 5) {
case 0:
du_0++;
break;
case 1:
du_1++;
break;
case 2:
du_2++;
break;
case 3:
du_3++;
break;
}
}
System.out.println("so cac so chia het cho 5 la: " + du_0);
System.out.println("So cac so chia 5 du 1 la: " + du_1);
System.out.println("So cac so chia 5 du 2 la: " + du_2);
System.out.println("So cac so chia 5 du 3 la: " + du_3);
}
}
Result - Kết Quả:
No comments:
Post a Comment