顯示具有 TQC plus JAVA 6 第二類 標籤的文章。 顯示所有文章
顯示具有 TQC plus JAVA 6 第二類 標籤的文章。 顯示所有文章

210 鍵盤字元判斷

import java.util.*;
class JPA210 {
    static Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
        test();
        test();
        test();
    }

    public static void test() {
        String s;
        System.out.println("Input a character :");
        s=keyboard.next();
switch(s){
case "a":
case "b":
System.out.println("You entered a or b");break;
case "x":
System.out.println("You entered x");break;
case "y":
System.out.println("You entered y");break;
default:
System.out.println("You entered something else.");break;
}
        
    }
}

209 象限座標

import java.util.*;
public class JPA209 {
    static Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
        test();
        test();
    }

    public static void test() {
double x,y;
System.out.print("請輸入X座標 : ");
x=keyboard.nextDouble();
System.out.print("請輸入y座標 : ");
y=keyboard.nextDouble();
if(x>0&&y>0){
System.out.println("("+x+","+y+")在第一象限");
}
else if(y==0&&x!=0){
System.out.println("("+x+","+y+")在x軸上");
}
else if(x>0&&y<0){
System.out.println("("+x+","+y+")在第四象限");
}
else if(x<0&&y>0){
System.out.println("("+x+","+y+")在第二象限");
}
else if(x==0&&y!=0){
System.out.println("("+x+","+y+")在y軸上");
}
else if(x<0&&y<0){
System.out.println("("+x+","+y+")在第三象限");
}
else{
System.out.println("("+x+","+y+")在原點");
}
    }
}

208 分級制度

import java.util.*;
import java.io.*;
class JPA208 {
    static Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args) {
    try{
        test();
        test();
        test();
        test();
        test();
    }
    catch(IOException e){
    }

    }

    public static void test() throws IOException {
        System.out.println("Input:");
        int x = keyboard.nextInt();
        if(x>=90){
        System.out.println("Ypur grade is A");
        }
        else if(x<90&&x>=80){
        System.out.println("Ypur grade is B");
        }
        else if(x<80&&x>=70){
        System.out.println("Ypur grade is c");
        }
        else if(x<70&&x>=60){
        System.out.println("Ypur grade is D");
        }
        else{
        System.out.println("Ypur grade is F");
        }
    }
}

207 三角形邊長判斷

import java.util.*;
public class JPA207 {
    static Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
        test();
        test();
    }

    static void test() {
double a,b,c;
System.out.println("請輸入三個整數:");
a=keyboard.nextDouble();
b=keyboard.nextDouble();
c=keyboard.nextDouble();

double x[]={a,b,c};
  Arrays.sort(x);
  a=x[0];
b=x[1];
  c=x[2];//c is max

if((a+b<=c)||a<=0||b<=0||c<=0){
System.out.println("不可以構成三角形");
}
else if((Math.pow(a,2)+Math.pow(b,2))==Math.pow(c,2)){
System.out.println("直角三角形");
}
else if((Math.pow(a,2)+Math.pow(b,2))<Math.pow(c,2)){
System.out.println("頓角三角形");
}
else{
System.out.println("銳角三角形");
}

    }
}

206 及格分數

import java.util.*;
public class JPA206 {
    static Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
        test();
        test();
    }

    static void test() {
        int chi, eng, math, avg;
        System.out.print("Input Chinese score:");
        chi = keyboard.nextInt();
        System.out.print("Input English score:");
        eng = keyboard.nextInt();
        System.out.print("Input Math score:");
        math = keyboard.nextInt();

        if(chi>=60&&eng>60&&math>=60){
        System.out.println("All Pass.");
        }
        if(chi<60){
        System.out.println("Chinese failed");
        }
        if(eng<60){
        System.out.println("English failed");
        }
        if(math<60){
        System.out.println("Math failed");
        }
    }
}

205 倍數判斷

import java.util.*;
public class JPA205 {
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
        test();
        test();
    }

    static void test() {
        System.out.println("Enter an integer:");
        int x=input.nextInt();
        if(x%6==0){
        System.out.println(x+"是2、3、6的倍數");
        }
        else if(x%2==0){
        System.out.println(x+"是2的倍數");
        }
        else if(x%3==0){
        System.out.println(x+"是3的倍數");
        }
        else{
        System.out.println(x+"不是2、3、6的倍數");
        }
    }
}

204 公倍數計算

import java.util.*;
class JPA204 {
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
    }

    public static void test() {
        System.out.println("Input:");
int x=input.nextInt();
        if(x%5==0&&x%9==0){
        System.out.println("Yes");
        }
        else{
        System.out.println("No");
        }
    }
}

203 判斷奇偶數

import java.util.*;
public class JPA203 {
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
    }

    static void test() {
        System.out.println("Input an integer:");
        if((input.nextInt()%2)==0){
        System.out.println("The number is even.");
        }
        else{
        System.out.println("The number is odd.");
        }
    }
}

202 比較大小

import java.util.*;
class JPA202 {
    static Scanner keyboard = new Scanner(System.in);
    public static void main(String[] args) {
        test();
        test();
    }

    public static void test() {
    int x,y;
        System.out.println("Input:");
        x=keyboard.nextInt();
        y=keyboard.nextInt();
        if(x>y){
        System.out.println(x+" is larger than "+y);
        }
        else{
        System.out.println(y+" is larger than "+x);
        }
    }
}

201 分數篩選

import java.util.Scanner;
public class JPA201 {
    static Scanner keyboard = new Scanner(System.in);

    public static void main(String[] args) {
        test();
        test();
    }

    public static void test() {
        System.out.println("Please enter score:");
        if(keyboard.nextDouble()>60){
        System.out.println("You pass");
        }
        System.out.println("End");
    }
}

   
    static double calRectangle(double x,double y) {
        return x*y/2;
    }
}