標題:
2023/11/04 上課重點(模擬考)
[打印本頁]
作者:
鄭繼威
時間:
2023-11-4 10:55
標題:
2023/11/04 上課重點(模擬考)
本帖最後由 鄭繼威 於 2023-11-4 12:02 編輯
抽考TQC+
Java 104 距離計算
Java 105 字串索引
Java 106 最大及最小值
Java 202 判斷奇偶數
Java 205 最大公因數
請將程式碼上傳
上傳範例:
[104]程式碼
[205]程式碼
TQC+官網
本認證為操作題,總分為100分。
操作題為第一至三類各考一題共三大題,第一大題至第二大題每題30分,第三大題每題40分,總計100分。
於認證時間60分鐘內作答完畢,成績加總達70分(含)以上者該科合格。
上課錄影
作者:
高昀昊
時間:
2023-11-4 11:47
104
import java.util.Scanner;
public class JPA104{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
Double x1,x2,y1,y2;
try{
x1=s.nextDouble();
y1=s.nextDouble();
x2=s.nextDouble();
y2=s.nextDouble();
}
catch(Exception e){
System.out.print("error");
s.close();
return;
}
s.close();
System.out.printf("%.4f", Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2)));
}
}
複製代碼
105
複製代碼
106
import java.util.Scanner;
public class JPA106{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
int a[]={0,0,0,0};
int big,small;
for(int i=0;i<=3;i++){
try{
a[i]=s.nextInt();
}
catch(Exception e){
a[i]=0;
s.next();
}
}
s.close();
big=a[0]>a[1]?a[0]:a[1];
big=big>a[2]?big:a[2];
big=big>a[3]?big:a[3];
small=a[0]<a[1]?a[0]:a[1];
small=small<a[2]?small:a[2];
small=small<a[3]?small:a[3];
System.out.println("smallest:"+small);
System.out.println("largest:"+big);
}
}
複製代碼
202
import java.util.Scanner;
public class JPA202{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
int a;
try{
a=s.nextInt();
}
catch(Exception e){
System.out.print("error");
s.close();
return;
}
s.close();
if(a%2==0){
System.out.print(a+" is an even number.");
}else{
System.out.print(a+" is an odd number.");
}
}
}
複製代碼
205
import java.util.Scanner;
public class JPA205{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
int a,b=0;
try{
a=s.nextInt();
}
catch(Exception e){
System.out.print("error");
s.close();
return;
}
try{
b=s.nextInt();
}
catch(Exception e){
System.out.print("error");
s.close();
return;
}
s.close();
if(a<0||a==0){
System.out.print("error");
return;
}
if(b<0||b==0){
System.out.print("error");
return;
}
for(int i=b;i>=1;i--){
if(a%i==0 && b%i==0){
System.out.print(i);
return;
}
}
}
}
複製代碼
作者:
高鋐鈞
時間:
2023-11-4 12:03
本帖最後由 高鋐鈞 於 2023-11-4 12:06 編輯
104
import java.util.*;
public class Ch05 {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
Double x1,x2,y1,y2;
try{
x1=s.nextDouble();
y1=s.nextDouble();
x2=s.nextDouble();
y2=s.nextDouble();
System.out.printf("%.4f",Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}catch(Exception e){
System.out.println("error");
s.close();
}
}
}
複製代碼
105
import java.util.*;
public class Ch01 {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
String dreams = "There are moments in life when you miss someone so much that "
+ "you just want to pick them from your dreams and hug them for real! Dream what "
+ "you want to dream;go where you want to go;be what you want to be,because you have "
+ "only one life and one chance to do all the things you want to do";
String search=s.nextLine();
int first,last;
String capture;
first=dreams.indexOf(search);
last=dreams.lastIndexOf(search);
if(first==-1){
first=0;
last=0;
capture="";
}else if(first==last){
last=0;
capture=dreams.substring(first);
first++;
}else {
capture=dreams.substring(first, last+search.length());
first++;
last++;
}
System.out.println("first:"+first);
System.out.println("last:"+last);
System.out.println("capture:"+capture);
}
}
複製代碼
106
import java.util.*;
public class Ch02 {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int a,b,c,d;
try{
a=s.nextInt();
if(a<0)
a=0;
}catch(Exception e){
a=0;
s.next();
}try{
b=s.nextInt();
if(b<0)
b=0;
}catch(Exception e){
b=0;
s.next();
}try{
c=s.nextInt();
if(c<0)
c=0;
}catch(Exception e){
c=0;
s.next();
}try{
d=s.nextInt();
if(d<0)
d=0;
}catch(Exception e){
d=0;
}
int tep1,tep2;
tep1=Math.min(a, b);
tep1=Math.min(tep1, c);
tep1=Math.min(tep1, d);
tep2=Math.max(a, b);
tep2=Math.max(tep2, c);
tep2=Math.max(tep2, d);
System.out.println("smallest:"+tep1);
System.out.println("largest:"+tep2);
}
}
複製代碼
202
import java.util.*;
public class Ch03 {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int a;
try{
a=s.nextInt();
}catch(Exception e){
System.out.println("error");
return;
}
if(a%2==0){
System.out.println(a+" is an even number.");
}else{
System.out.println(a+" is an odd number.");
}
}
}
複製代碼
205
import java.util.Scanner;
public class Ch04 {
public static void main(String args[]) {
Scanner s=new Scanner(System.in);
int a,b;
try{
a=s.nextInt();
b=s.nextInt();
if(a<0||a>100||b<0||b>100){
System.out.println("error");
return;
}
}catch(Exception e){
System.out.println("error");
return;
}
int x=0;
for(int i=1;i<=Math.max(a, b);i++){
if(a%i==0&&b%i==0){
x=i;
}
}
System.out.print(x);
}
}
複製代碼
作者:
孫子傑
時間:
2023-11-4 12:06
[code]import java.util.*;
public class Ch01 {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Scanner s=new Scanner(System.in);
double x1=0,x2=0,y1=0,y2=0;
double df;
try
{
x1=s.nextDouble();
y1=s.nextDouble();
x2=s.nextDouble();
y2=s.nextDouble();
}catch(Exception e){
System.out.println("error");
return;
}
df=Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
System.out.printf("%.4f",df);
}
}
複製代碼
import java.util.*;
public class Ch02 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
String dreams = "There are moments in life when you miss someone so much that "
+ "you just want to pick them from your dreams and hug them for real! Dream what "
+ "you want to dream;go where you want to go;be what you want to be,because you have "
+ "only one life and one chance to do all the things you want to do";
String sea="",res="";
int fir=0,la=0;
sea=s.nextLine();
fir=dreams.indexOf(sea);
la=dreams.lastIndexOf(sea);
if(fir==-1){
fir=0;
la=0;
}
else
{
if(fir==la)
{
res=dreams.substring(fir);
la=0;
fir+=1;
}
else
{
res=dreams.substring(fir,la+sea.length());
la+=1;
fir+=1;
}
}
System.out.println("first:"+fir);
System.out.println("last:"+la);
System.out.println("capture:"+res);
}
}
複製代碼
import java.util.*;
public class Ch03 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int a=0,b=0,c=0,d=0,ef=0,f=0;
try
{
a=s.nextInt();
if(a<0)
a=0;
}
catch(Exception e)
{
a=0;
s.next();
}
try
{
b=s.nextInt();
if(b<0)
b=0;
}
catch(Exception e)
{
b=0;
s.next();
}
try
{
c=s.nextInt();
if(c<0)
c=0;
}
catch(Exception e)
{
c=0;
s.next();
}
try
{
d=s.nextInt();
if(d<0)
d=0;
}
catch(Exception e)
{
d=0;
s.next();
}
if(a>b)
ef=a;
else
ef=b;
if(c>ef)
ef=c;
if(d>ef)
ef=d;
if(a>b)
f=b;
else
f=a;
if(f>c)
f=c;
if(f>d)
f=b;
System.out.println("smallest:"+f);
System.out.println("largest:"+ef);
}
}
複製代碼
import java.util.*;
public class Ch04 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int a=0,b=0,c=0;
try
{
a=s.nextInt();
}catch(Exception e)
{
System.out.println("error");
return;
}
try
{
b=s.nextInt();
}catch(Exception e)
{
System.out.println("error");
return;
}
if(a>b)
c=b;
else
c=a;
for(int i=0;i<c;i++)
{
if(a%i && b)
}
}
}
複製代碼
import java.util.*;
public class Ch5 {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Scanner s=new Scanner(System.in);
int a=0;
try
{
a=s.nextInt();
}catch(Exception e)
{
System.out.println("error");
return;
}
if(a%2==0)
System.out.println(a+" is an even number.");
else
System.out.println(a+" is an odd number.");
}
}
複製代碼
作者:
利勁鋼
時間:
2023-11-4 12:09
104
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
try{
double x, a, y, b,length;
Scanner sc=new Scanner(System.in);
x=sc.nextDouble();
y=sc.nextDouble();
a=sc.nextDouble();
b=sc.nextDouble();
length=Math.sqrt(((x-a)*(x-a))+((y-b)*(y-b)));
System.out.printf("%.4f",length);
}catch(Exception e){
System.out.print("error");
System.exit(0);
}
}
}
複製代碼
106
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int k1,k2,k3,k4;
k1=0;
k2=0;
k3=0;
k4=0;
try{
k1=sc.nextInt();
if(k1<0)
k1=0;
}catch(Exception e){
sc.next();
try{
k2=sc.nextInt();
if(k2<0)
k2=0;
}catch(Exception e){
sc.next();
}
try{
k3=sc.nextInt();
if(k3<0)
k3=0;
}catch(Exception e){
sc.next();
}
try{
k4=sc.nextInt();
if( k4<0)
k4=0;
}catch(Exception e) {
sc.next();
}
int s=k1<k2?k1:k2;
s=s<k3?s:k3;
s=s<k4?s:k4;
int l=k1>k2?k1:k2;
l=l>k3?l:k3;
l=l>k4?l:k4;
System.out.println("smallest:" + s);
System.out.print("largest:" + l);
}
}
}
複製代碼
202
import java.util.Scanner;
public class JPA02 {
public static void main(String[] args) {
int n;
try {
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
} catch (Exception e) {
System.out.println("error");
return;
}
if(n%2==0)
System.out.print(n+" is an even number.");
else
System.out.print(n+" is an odd number.");
}
}
複製代碼
205
public class Main
{
public static void main(String[] args) {
public static void main(String[] args) {
int a, b;
try {
Scanner sc = new Scanner(System.in);
a=sc.nextInt();
b=sc.nextInt();
if(a<0 || a>100 || b<0 || b>100 )
{
System.out.print("error");
return;
}
} catch (Exception e) {
System.out.print("error");
return;
}
while(a%b!=0)
{
int tmp=a%b;
a=b;
b=tmp;
}
System.out.println(b);
}
}
複製代碼
作者:
柳侑辰
時間:
2023-11-4 12:10
104
import java.util.*;
public class Ch6 {
public static void main(String args[]){
Scanner s=new Scanner(System.in);
double x1,x2,y1,y2,dis=0;
try{
x1=s.nextDouble();
y1=s.nextDouble();
x2=s.nextDouble();
y2=s.nextDouble();
dis=Math.sqrt(Math.pow(x1-x2, 2)+Math.pow(y1-y2, 2));
System.out.printf("%.4f",dis);
}catch(Exception e){
System.out.printf("error");
}
}
}
複製代碼
106
import java.util.*;
public class Ch666 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int a,b,c,d,largest=0,smallest=0;
try{
a=s.nextInt();
if(a<0)
{
a=0;
}
}catch(Exception e)
{
a=0;
s.next();
}try{
b=s.nextInt();
if(b<0)
{
b=0;
}
}catch(Exception e)
{
b=0;
s.next();
}try{
c=s.nextInt();
if(c<0)
{
c=0;
}
}catch(Exception e)
{
c=0;
s.next();
}try{
d=s.nextInt();
if(d<0)
{
d=0;
}
}catch(Exception e)
{
d=0;
s.next();
}
if(a>b)
{
if(a>c)
{
if(a>d)
{
largest=a;
}else
{
largest=d;
}
}else
{
if(c>d)
{
largest=c;
}else
{
largest=d;
}
}
}else
{
if(b>c)
{
if(b>d)
{
largest=b;
}else
{
largest=d;
}
}else
{
if(c>d)
{
largest=c;
}else
{
largest=d;
}
}
}if(a<b)
{
if(a<c)
{
if(a<d)
{
smallest=a;
}else
{
smallest=d;
}
}else
{
if(c<d)
{
smallest=c;
}else
{
smallest=d;
}
}
}else
{
if(b<c)
{
if(b<d)
{
smallest=b;
}else
{
smallest=d;
}
}else
{
if(c<d)
{
smallest=c;
}else
{
smallest=d;
}
}
}
System.out.println("smallest:"+smallest);
System.out.println("largest:"+largest);
}
}
複製代碼
202
import java.util.Scanner;
public class Ch6666 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int x;
try{
x=s.nextInt();
}catch(Exception e)
{
System.out.println("erorr");
return;
}
if(x%2==1)
{
System.out.println(x+" is an odd number");
}else
{
System.out.println(x+" is an even number");
}
}
}
複製代碼
205
import java.util.Scanner;
public class Ch66666 {
public static void main(String args[]){
Scanner s=new Scanner(System.in);
int a,b,dis=0;
try{
a=s.nextInt();
b=s.nextInt();
if(a<0 || a>100)
{
System.out.println("error");
return;
}
if(b<0 || b>100)
{
System.out.println("error");
return;
}
}catch(Exception e){
System.out.printf("error");
return;
}
for(int i=a;i>=1;i--)
{
if(a%i==0 && b%i==0)
{
dis=i;
break;
}
}
System.out.print(dis);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2