วันอาทิตย์, มิถุนายน 1, 2025
Latest:
วิชาภาษาจาวา (java)

การใช้คำสั่ง if ภาษาจาวา (java)

ในภาษาจาวานั้นคำสั่ง if จะใช้ในการเปรียบเทียบค่าความจริง หรือค่าความเท็จ โดยมีการสร้างเงื่อนไขขึ้นมา ข้อควรจำเมื่อเรียกใช้งานคำสั่ง if คือจะทำงานก็ต่อเมื่อเงื่อนไขใน if มีค่าความจริงเป็นจริง หากมีค่าเป็นเท็จขึ้นมาคำสั่งจะไม่มีการทำงาน นอกเสียจากจะเรียกใช้คำสั่ง if else

โครงสร้างคำสั่ง if ภาษา java

if (เงื่อนไข){

}

ตัวอย่างคำสั่ง if ภาษา java

class Testif 
{
	public static void main(String[] args) 
	{
		int x = 20;
		int y = 17;
		if (x > y) {
			System.out.println("printif");
	}
	}
}
slot gacor hari ini slot qris slot gacor maxwin slot online slot gacor gampang menang slot gacor hari ini slot online slot slot slot guci777 wortel21 guci777 guci777 wortel21 wortel21 wortel21