ประโยคเงื่อนไข
เงื่อนไข คือ ข้อตกลงในการตัดสินใจอะไรสักอย่าง
เช่น
การเป็นคนดีอาจจะมีเงื่อนไขว่า ต้องไม่ทำชั่ว
แต่ถ้าหากทำชั่วก็จะไม่ใช่คนดี
ในjava ใช้ if ถ้าผล =>T จะให้ผลตามที่ตกลง
ถ้าผล =>F จะให้ผลเป็นอย่างอื่นหรือไม่ให้ผล
public class if1 {
public static void main(String[]args) {
int x= 5;
if(x==5) System.out.println("x="+x);
System.out.println("bye bye"); } }
จากสมการข้างต้น ที่ให้x=5
................................................................
public class if2 {
public static void main(String[]args) {
int x= 10;
if(x==5) { System.out.println("x="+x);
System.out.println("Condition=true"); }
else System.out.println("x is not equal to 10");
System.out.println("bye bye"); } }
...............................................................
import java.util.*;
public class if3 {
public static void main(String[]args){
Scanner a = new Scanner(System.in);
int x ;
System.out.print("enter the number : ");
x = a.nextInt();
if(x==120) { System.out.println("x="+x);
System.out.println("jack pot"); }
else System.out.println("fail");
System.out.println("bye bye"); }}
down load here
http://www.uploadtoday.com/download/?25b1e416996157b70053e11c811f6220
วันพฤหัสบดีที่ 30 สิงหาคม พ.ศ. 2550
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)
ไม่มีความคิดเห็น:
แสดงความคิดเห็น