การใช้else
else เป็นการนำคำสั้งของเงื่อนไข เมื่อสิ่งที่มาจาก if=>F
import java.util.*;
public class numberif{
public static void main(String[] args) {
int num1 = new Scanner(System.in).nextInt();
if(num1 == 50) System.out.println(" the number = " + 50);
else if(num1 > 50 ) System.out.println(" the number > 50 ");
else System.out.println(" the number < 50 "); } }
down load
http://www.uploadtoday.com/download/?35a650703f1dbf43ad0eb1b27c32e8be
วันพฤหัสบดีที่ 30 สิงหาคม พ.ศ. 2550
week5
ประโยคเงื่อนไข
เงื่อนไข คือ ข้อตกลงในการตัดสินใจอะไรสักอย่าง
เช่น
การเป็นคนดีอาจจะมีเงื่อนไขว่า ต้องไม่ทำชั่ว
แต่ถ้าหากทำชั่วก็จะไม่ใช่คนดี
ใน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
เงื่อนไข คือ ข้อตกลงในการตัดสินใจอะไรสักอย่าง
เช่น
การเป็นคนดีอาจจะมีเงื่อนไขว่า ต้องไม่ทำชั่ว
แต่ถ้าหากทำชั่วก็จะไม่ใช่คนดี
ใน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
week3
เรียน การรวมข้อความ การคำนวณในภาษา java
ตัวอย่างงาน
public class sumScore {
public static void main(String[]args) {
System.out.println(args[0]);
System.out.println("score1="+args[1]);
System.out.println("score2="+args[2]);
System.out.println(Integer.parseInt(args[1])+Integer.parseInt(args[2]));
}
}
down load here
http://www.uploadtoday.com/download/?99a10609b58dc13274ba4608e6389b4b
ตัวอย่างงาน
public class sumScore {
public static void main(String[]args) {
System.out.println(args[0]);
System.out.println("score1="+args[1]);
System.out.println("score2="+args[2]);
System.out.println(Integer.parseInt(args[1])+Integer.parseInt(args[2]));
}
}
down load here
http://www.uploadtoday.com/download/?99a10609b58dc13274ba4608e6389b4b
week2
เรียนรู้ การประมวลผลใน java
public class jak_week2 {
public static void main(String [] args){
System.out.println("Rectangle area = 1/2 * base / hight" );
System.out.println("Base = " + 10 );
System.out.println("Hight = " + 20 );
System.out.println("Rectangle area = " + ( 1.0/2 * 10 * 20 ) );
}
}
down load here
http://www.uploadtoday.com/download/?30a781f4c34e1a5e704829951a1e79f3
public class jak_week2 {
public static void main(String [] args){
System.out.println("Rectangle area = 1/2 * base / hight" );
System.out.println("Base = " + 10 );
System.out.println("Hight = " + 20 );
System.out.println("Rectangle area = " + ( 1.0/2 * 10 * 20 ) );
}
}
down load here
http://www.uploadtoday.com/download/?30a781f4c34e1a5e704829951a1e79f3
สมัครสมาชิก:
บทความ (Atom)