Proposition => Write "playing card" function which takes a card value(1-13) and prints the correct value (2-10,'jack','queen','king','Ace').Use the function in a main() program.
Translated into Thailand => เขียน ฟังก์ชันที่ใช้ค่าของไพ่(1-13) และพิมพ์ค่าที่ถูกต้อง (2-10,'jack','queen','king','Ace').
Solution=>
void setup() {
Correct(1);
}
void Correct(int x) { //เป็นฟังก์ชันที่มี parameter โดยภายในฟังก์ชันมีการเก็บเงื่อนไขต่างๆที่จะใช้
แสดงค่าที่ถูกต้องของไพ่
if (x==1) {
println("Ace"); //คำสั่งที่ใช้แสดงข้อความออกทางหน้าจอ
}
else if (x==11) {
println("jack");
}
else if (x==12) {
println("queen");
}
else if (x==13) {
println("king");
}
else {
println(x);
}
}
You can run code in http://processingjs.org/tools/processing-helper.html
text book name :Programming and problem solving with Java – 2nd edition
Author : Nell Dale and Chip Weems
ISBN 978-0-7637-3402-2
Translated into Thailand => เขียน ฟังก์ชันที่ใช้ค่าของไพ่(1-13) และพิมพ์ค่าที่ถูกต้อง (2-10,'jack','queen','king','Ace').
Solution=>
void setup() {
Correct(1);
}
void Correct(int x) { //เป็นฟังก์ชันที่มี parameter โดยภายในฟังก์ชันมีการเก็บเงื่อนไขต่างๆที่จะใช้
แสดงค่าที่ถูกต้องของไพ่
if (x==1) {
println("Ace"); //คำสั่งที่ใช้แสดงข้อความออกทางหน้าจอ
}
else if (x==11) {
println("jack");
}
else if (x==12) {
println("queen");
}
else if (x==13) {
println("king");
}
else {
println(x);
}
}
You can run code in http://processingjs.org/tools/processing-helper.html
text book name :Programming and problem solving with Java – 2nd edition
Author : Nell Dale and Chip Weems
ISBN 978-0-7637-3402-2
ไม่มีความคิดเห็น:
แสดงความคิดเห็น