Bài 1:Tổng quan về java
Saturday, May 14, 2016
/
No Comments
<java>Bài 1:Tổng quan về java
1.1 Hello would
public class Hello_would
{
public static void main(String[] args){
System.out.println("Hello Would");
}
}
{
public static void main(String[] args){
System.out.println("Hello Would");
}
}
1.2 If - Else
public class If_else
{
public static void main(String[] args){
int x = 2;
if( x % 2 == 0){
System.out.println("X là số chẵn");
}
else System.out.println("X là số lẻ");
}
}
Kết quả: X là số chẵn
{
public static void main(String[] args){
int x = 2;
if( x % 2 == 0){
System.out.println("X là số chẵn");
}
else System.out.println("X là số lẻ");
}
}
Kết quả: X là số chẵn
1.3 Loop
public class Loop
{
public static void main(String[] args){
for(int i = 1;i < 10; i++){
System.out.print(i + "\t");
}
System.out.print("\n")
int i = 1;
while(i < 10){
System.out.print(i + "\t");
i++; }
System.out.print("\n");
int j = 1;
do{
System.out.print(j + "\t");
j++;
}
while(j < 10);
}
}
{
public static void main(String[] args){
for(int i = 1;i < 10; i++){
System.out.print(i + "\t");
}
System.out.print("\n")
int i = 1;
while(i < 10){
System.out.print(i + "\t");
i++; }
System.out.print("\n");
int j = 1;
do{
System.out.print(j + "\t");
j++;
}
while(j < 10);
}
}
Kết quả : 1 2 3 4 5 6 7 8 9