本帖最後由 張健勳 於 2017-7-8 10:03 編輯
- import java.util.Scanner;
- public class JPD01 {
-
- static Scanner scanner = new Scanner(System.in);
-
- public static void main(String[] args)
- {
-
- System.out.println("Please input: ");
- float n1 = scanner.nextInt();
- float n2 = scanner.nextInt();
- float n3 = scanner.nextInt();
-
- float total = (n1+n2+n3);
- float avg = total/3;
-
- System.out.println(avg);
-
-
-
-
- }
- }
複製代碼- import java.util.*;
- public class JPD02 {
- 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 interger: ");
- int n = input.nextInt();
-
- if ( n%2==0 || n%3 ==0 || n%6 ==0 )
- {
- System.out.println(n+"是2,3,6的倍數");
- }else if ( n%2==0 ){
- System.out.println(n+"是2的倍數");
- }else if ( n%3==0 ){
- System.out.println(n+"是3的倍數");
- }else if ( n%6==0 ){
- System.out.println(n+"是6的倍數");
- }else{
- System.out.println(n+"不是2,3,6的倍數");
- }
- }
- }
複製代碼- import java.util.*;
- public class JPA02 {
- static Scanner keyboard = new Scanner(System.in);
- public static void main(String[] args) {
- test();
- test();
- test();
- test();
- }
-
- static void test() {
-
- System.out.println("請輸入三個數字 : ");
- int x = keyboard.nextInt();
- int y = keyboard.nextInt();
- int z = keyboard.nextInt();
-
-
- if(x+y>z && x+z>y && y+z>x)
- {
- if(x*x + y*y == z*z)
- System.out.println("直角三角形");
- else if(x*x + y*y < z*z)
- System.out.println("鈍角三角形");
- else if(x*x + y*y > z*z)
- System.out.println("銳角三角形");
- }
- else
- {
- System.out.println("不可以構成三角形");
- }
- }
-
- }
複製代碼- public class JPA03{
- public static void main(String argv[]) {
-
- int i, num, sum = 0;
-
- System.out.printf("1~1000中的完美數有: ");
-
- for (i=1;i<=1000;i++){
-
- sum=0;
-
- for (num=1;num<i;num++) {
-
- if (i%num==0)sum+=num;
-
- }
-
- if (i==sum) {
-
- System.out.printf("%d ",num);
-
- }
-
- }
-
- System.out.printf("\n");
-
- }
- }
複製代碼- import java.util.Scanner;
- public class JPA03 {
-
-
- public static void main(String[] args) {
- int total = 0;
- int s = 0;
- int count = 0;
- double average;
-
- Scanner scanner = new Scanner(System.in);
- while(true){
- System.out.print("Please enter meal dollars or enter -1 to stop: ");
-
- s = scanner.nextInt();
- if (s==-1){
- break;
-
- }else{
- total+=s;
- count++;
- }
- }
- average = (double)total/count;
-
- System.out.println("餐點總費用:"+total);
- System.out.printf(" %d 道餐點平均費用為: %.2f %n",count,average);
-
- }
- }
複製代碼- import java.io.*;
- import java.util.Scanner;
- public class JPA03 {
- public static void main (String argv[]) throws IOException {
-
- Scanner scanner = new Scanner(System.in);
-
- int num1, num2;
-
- System.out.println("Input:");
-
- num1 = scanner.nextInt();
- while (num1!=999) {
- num2=scanner.nextInt();
- System.out.println(gcd(num1,num2));
- System.out.println("Input:");
- num1=scanner.nextInt();
- }
- }
-
- static int gcd (int m, int n) {
- int result;
- while (m%n!=0){
- result = n;
- n = m%n;
- m = result;
- }
- return n;
- }
-
-
- }
複製代碼 |