標題:
請各位學員準備,下次上課要考試唷!
[打印本頁]
作者:
顏子翔
時間:
2019-3-23 15:21
標題:
請各位學員準備,下次上課要考試唷!
下次上課將會先行測驗 308 以及 402 唷
請各位學員準備
作者:
高允懋
時間:
2019-3-30 13:56
import java.util.Scanner;
public class JPA03 {
static Scanner keyboard = new Scanner(System.in);
static int i = -1;
public static void main(String[] args) {
int total = 0, s = 0;
do {
System.out.print("請輸入消費金額,或輸入-1結束:");
s = keyboard.nextInt();
total += s;
} while (s != -1);
System.out.println("電腦週邊總消費:" + (total + 1));
}
}
複製代碼
作者:
黃安立
時間:
2019-3-30 13:59
import java.util.Scanner;
public class JP03 {
static Scanner keyboard = new Scanner(System.in);
static int i = -1;
public static void main(String[] args) {
int total = 0, s = 0;
do
{
System.out.print("請輸入消費金額,或輸入-1結束:");
s=keyboard.nextInt();
total+=s;
}while(s!=i);
System.out.println("電腦周邊總消費:"+(total+1));
}
}
複製代碼
作者:
吳秉翰
時間:
2019-3-30 14:02
import java.util.Scanner;
public class JPA03 {
static Scanner keyboard = new Scanner(System.in);
static int i = -1;
public static void main(String[] args) {
int total = 0, s = 0;
do{
System.out.print("請輸入消費金額,或輸入-1結束:");
s=keyboard.nextInt();
total+=s;
}while(s!=-1);
System.out.println("電腦週邊總消費:"+(total+1));
}
}
複製代碼
作者:
彭煥宇
時間:
2019-3-30 14:03
import java.util.Scanner;
public class JPA03 {
static Scanner keyboard = new Scanner(System.in);
static int i = -1;
public static void main(String[] args) {
int total = 0, s = 0;
do{
total+=s;
System.out.print("請輸入消費金額,或輸入-1結束 ");
s=keyboard.nextInt();
}while(s!=-1);
System.out.print(total);
}
}
複製代碼
作者:
高允懋
時間:
2019-3-30 14:15
import java.util.Scanner;
public class JPA04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
while (true) {
System.out.print("Input n (0 <= n <= 16): ");
int n = keyboard.nextInt();
if (n == 999)
break;
System.out.printf("%d 的階乘(尾端遞迴) = %d\n", n, Tail(n, 1));
System.out.printf("%d 的階乘(迴圈) = %d\n", n, Loop(n, 1));
}
}
public static int Tail(int n, int m) {
if (n == 1)
return m;
else
return Tail(n - 1, m * n);
}
public static int Loop(int n, int m) {
while (n > 1) {
m *= n;
n--;
}
return m;
}
}
複製代碼
作者:
吳秉翰
時間:
2019-3-30 14:44
import java.util.Scanner;
public class JPA04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
int n = 0;
System.out.print("Input n (0 <= n <=16):");
n = keyboard.nextInt();
while (n != 999) {
System.out.println(n + "的階乘(尾端遞迴)=" + fac(n));
System.out.println(n + "的階乘(迴圈)=" + facLoop(n, 1));
System.out.print("Input n (0 <= n <=16):");
n = keyboard.nextInt();
}
}
static int fac(int n) {
if (n == 0) {
return 1;
} else {
return n * fac(n - 1);
}
}
static int facLoop(int n, int m) {
while (n != 0) {
m = m * n;
n--;
}
return m;
}
}
複製代碼
作者:
黃安立
時間:
2019-3-30 15:19
import java.util.Scanner;
public class JPD04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
System.out.println("Input n(0<=n<=16):");
int n = keyboard.nextInt();
while (n != 999) {
System.out.println(n + "的階乘(尾端遞迴)=" + fac(n, 1));
System.out.println(n + "的階乘(迴圈)=" + facloop(n, 1));
System.out.println("Input n(0<=n<=16):");
n = keyboard.nextInt();
}
}
static int fac(int n, int r) {
if (n == 0)
return r;
else
return fac(n - 1, r * n);
}
static int facloop(int n, int r) {
while (n != 0) {
r = r * n;
n--;
}
return r;
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2