Skip to content

Instantly share code, notes, and snippets.

@Terng
Created October 13, 2017 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Terng/2ac25b44c37f38676e69b80390c4da2d to your computer and use it in GitHub Desktop.
Save Terng/2ac25b44c37f38676e69b80390c4da2d to your computer and use it in GitHub Desktop.
โปรแกรมคำนวณค่า Taxi (Taxi Distance Calculate) กับ สุ่มตัวเลข
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);
}
}
}
}
@Terng
Copy link
Author

Terng commented Oct 13, 2017

ผลลัพธ์อันแรก
image
ผลลัพธ์อันที่สอง(ถ้าเกิดมันถูกมันจะแสดงคำว่า Guess Number ตามด้วยตัวเลขแต่อันนี่กูไม่ถูกสักที)
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment