Created
October 13, 2017 13:52
-
-
Save Terng/2ac25b44c37f38676e69b80390c4da2d to your computer and use it in GitHub Desktop.
โปรแกรมคำนวณค่า Taxi (Taxi Distance Calculate) กับ สุ่มตัวเลข
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.terng; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
System.out.println("Taxi Distance Calculate"); | |
int total; | |
double money,dis; | |
Scanner disIN = new Scanner(System.in); | |
System.out.print("Enter money : "); | |
dis = disIN.nextDouble(); | |
if (dis == 1) { | |
money = 35; | |
dis *= money; | |
total = (int) Math.ceil(dis); | |
dis = total; | |
System.out.println("You Expenses is : "+dis); | |
} | |
else if (dis >= 1 && dis <= 10) { | |
money = 5.5; | |
dis *= money; | |
total = (int) Math.ceil(dis); | |
dis = total; | |
System.out.println("You Expenses is : "+dis); | |
} | |
else if (dis >= 10 && dis <= 20) { | |
money = 6.5; | |
dis *= money; | |
total = (int) Math.ceil(dis); | |
dis = total; | |
System.out.println("You Expenses is : "+dis); | |
} | |
else if (dis >= 20 && dis <= 40) { | |
money = 7.5; | |
dis *= money; | |
total = (int) Math.ceil(dis); | |
dis = total; | |
System.out.println("You Expenses is : "+dis); | |
} | |
else if (dis >= 40 && dis <= 60) { | |
money = 8; | |
dis *= money; | |
total = (int) Math.ceil(dis); | |
dis = total; | |
System.out.println("You Expenses is : "+dis); | |
} | |
else if (dis >= 60) { | |
money = 10; | |
dis *= money; | |
total = (int) Math.ceil(dis); | |
dis = total; | |
System.out.println("You Expenses is : "+dis); | |
} | |
} | |
} | |
//////////////////// | |
package com.terng; | |
import java.util.Random; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Random r = new Random(); | |
Scanner in = new Scanner(System.in); | |
int low = 0; | |
int hight = 100; | |
int Result = r.nextInt(hight - low) + low; | |
int faknum; | |
System.out.println("Enter Guess Number between " + low + " and " + hight + " : "); | |
while (low != hight) { | |
faknum = in.nextInt(); | |
if (faknum < low || faknum > hight) { | |
System.out.println("Incorrect Number "); | |
} | |
else if (faknum > Result) { | |
System.out.println("Enter Guess Number between " + low + " and " + faknum + " : "); | |
} | |
else if (faknum < Result) { | |
System.out.println("Enter Guess Number between " + faknum + " and " + hight + " : "); | |
} | |
else if (faknum == Result) { | |
System.out.println("Guess Number is " + Result); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ผลลัพธ์อันแรก
ผลลัพธ์อันที่สอง(ถ้าเกิดมันถูกมันจะแสดงคำว่า Guess Number ตามด้วยตัวเลขแต่อันนี่กูไม่ถูกสักที)