News Ticker

Menu

Bài 1:Tổng quan về java

<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");

}

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

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);
}
}

Kết quả : 1 2 3 4 5 6 7 8 9

Share This:

Post Tags:

No Comment to " Bài 1:Tổng quan về java "

  • To add an Emoticons Show Icons
  • To add code Use [pre]code here[/pre]
  • To add an Image Use [img]IMAGE-URL-HERE[/img]
  • To add Youtube video just paste a video link like http://www.youtube.com/watch?v=0x_gnfpL3RM