標題:
TQC20220723模擬考一
[打印本頁]
作者:
葉桔良
時間:
2022-7-23 14:12
標題:
TQC20220723模擬考一
本帖最後由 葉桔良 於 2022-7-23 14:19 編輯
請將考試答案貼到這邊,並標示題號。
作者:
朱春男
時間:
2022-7-23 14:13
108
class JPA01 {
public static void main (String[] args) {
int i = add(2, 3);
double d = add(5.2, 4.3);
String s = add("I love ", "Java!!");
System.out.printf("%d %f %s %n", i, d, s);
}
static int add(int i,int j){
System.out.println("Adding two integers:"+i+","+j);
return i+j;
}
static double add(double i,double j){
System.out.println("Adding two doubles:"+i+","+j);
return i+j;
}
static String add(String i,String j){
System.out.println("Adding two strings:"+i+","+j);
return i+j;
}
}
複製代碼
作者:
朱春男
時間:
2022-7-23 14:14
208
import java.util.*;
class JPA02 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
test();
test();
test();
test();
test();
}
public static void test() {
int score=0;
System.out.println("Input:");
score=keyboard.nextInt();
if(score>=90)
System.out.println("Your grade is A");
else if(90>score && score>=80)
System.out.println("Your grade is B");
else if(80>score && score>=70)
System.out.println("Your grade is C");
else if(70>score && score>=60)
System.out.println("Your grade is D");
else
System.out.println("Your grade is F");
}
}
複製代碼
作者:
朱春男
時間:
2022-7-23 14:15
308
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;
System.out.print("請輸入消費金額,或輸入-1結束:");
s=keyboard.nextInt();
while(s!=-1){
total+=s;
System.out.print("請輸入消費金額,或輸入-1結束:");
s=keyboard.nextInt();
}
System.out.println("電腦週邊消費總額:"+total);
}
}
複製代碼
作者:
朱春男
時間:
2022-7-23 14:16
404
import java.util.Scanner;
public class JPA04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
int m,n;
System.out.print("Input m: ");
m=keyboard.nextInt();
while(m!=999){
System.out.print("Input n: ");
n=keyboard.nextInt();
System.out.println("最大公因數為:"+big(m,n));
System.out.print("Input m: ");
m=keyboard.nextInt();
}
}
static int big(int m,int n){
int tmp;
while(m%n!=0){
tmp=m%n;
m=n;
n=tmp;
}
return n;
}
}
複製代碼
作者:
朱春男
時間:
2022-7-23 14:17
504
import java.util.Scanner;
public class JPA05 {
public static Scanner keyboard = new Scanner(System.in);
public static void main(String[] argv) {
int data[] = new int[10];
data[0]=0;
data[1]=1;
for(int i=2;i<10;i++)
data[i]=data[i-1]+data[i-2];
for(int i=0;i<10;i++)
System.out.println(data[i]);
}
}
複製代碼
作者:
朱春珠
時間:
2022-7-23 14:17
108
class JPA01 {
static int add(int a,int b)
{
return a+b;
}
static double add(double c,double d)
{
return c+d;
}
static String add(String e,String f)
{
return e+f;
}
public static void main (String[] args) {
int i = add(2, 3);
double d = add(5.2, 4.3);
String s = add("I love ", "Java!!");
System.out.printf("%d %f %s %n", i, d, s);
}
}
複製代碼
作者:
朱春珠
時間:
2022-7-23 14:19
208
import java.util.*;
class JPA02 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
test();
test();
test();
test();
test();
}
public static void test() {
int x;
System.out.println("Input:");
x=keyboard.nextInt();
if(x>=90)
{
System.out.println("Your grade is A");
}
else if(x<90 && x>=80)
{
System.out.println("Your grade is B");
}
else if(x<80 && x>=70)
{
System.out.println("Your grade is C");
}
else if(x<70 && x>=60)
{
System.out.println("Your grade is D");
}
else
System.out.println("Your grade is F");
}
}
複製代碼
作者:
朱春珠
時間:
2022-7-23 14:20
308
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;
System.out.print("請輸入消費金額,或輸入-1結束:");
s=keyboard.nextInt();
do{
total+=s;
System.out.print("請輸入消費金額,或輸入-1結束:");
s=keyboard.nextInt();
}while(s!=-1);
System.out.print("電腦週邊總消費:"+total);
}
}
複製代碼
作者:
朱春珠
時間:
2022-7-23 14:21
404
import java.util.Scanner;
public class JPA04 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String args[]) {
int m=0,n=0;
System.out.print("Input m: ");
m=keyboard.nextInt();
while(m!=999)
{
System.out.print("Input n: ");
n=keyboard.nextInt();
System.out.println("最大公因數為:"+x(m,n));
System.out.print("Input m: ");
m=keyboard.nextInt();
}
}
static int x(int m,int n)
{
int t;
if(m%n==0)
return n;
else
{
return x(n,m%n);
}
}
}
複製代碼
作者:
朱春珠
時間:
2022-7-23 14:23
504
import java.util.Scanner;
public class JPA05 {
public static Scanner keyboard = new Scanner(System.in);
public static void main(String[] argv) {
int data[]=new int[10];
data[0]=0;
data[1]=1;
for(int i=2;i<10;i++)
{
data[i]=data[i-1]+data[i-2];
}
for(int i=0;i<10;i++)
{
System.out.println(data[i]);
}
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2