本帖最後由 孫文康 於 2024-1-20 17:23 編輯
304- import java.util.Scanner;
- public class JAVA{
- static int compute(int date[])
- {
- int sum=0;
- for(int i=0;i<6;i++)
- if(date[i]%3==0)
- sum++;
- return sum;
- }
- public static void main(String[] args)
- {
- int date[]=new int[6];
- Scanner s=new Scanner(System.in);
- for(int i=0;i<6;i++)
- date[i]=s.nextInt();
- System.out.println(compute(date));
- }
- }
複製代碼 306- import java.util.Scanner;
- public class JAVA
- {
- static int compute(int n)
- {
- if(n==1)
- return 1;
- else
- return n*compute(n-1);
- }
- public static void main(String[] args) {
- Scanner s=new Scanner (System.in);
- int n=s.nextInt();
- System.out.println(n+"!="+compute(n));
- }
- }
複製代碼 310- import java.util.Scanner;
- public class JAVA {
- static int compute(int n)
- {
- int total=0;
- for(int i=1; i<n; i++)
- {
- int sum=0;
- String str=String.valueOf(i);// int to string
- int len=str.length();//length() 得到字串長度
- for(int j=0; j<len; j++)
- {
- int t=str.charAt(j)-'0';//將各個數字轉換為int
- sum+=Math.pow(t, len);//並進行自身位數次方的動作
- }
- if(sum==i)//判斷是否為阿姆斯壯數
- {
- System.out.println(i);
- total+=i;
- }
- }
- return total;
- }
- public static void main(String[] args) {
- Scanner s=new Scanner(System.in);
- int n=s.nextInt();
- System.out.println(compute(n));
- }
- }
複製代碼 404- import java.util.Scanner;
- public class JAVA {
- public static void main(String[] args) {
- int sum[]=new int[26];
- Scanner s=new Scanner(System.in);
- String str=s.nextLine();
- int len=str.length(),maxV=0;
- char res=0;
- for(int i=0;i<len;i++)
- {
- char c=str .charAt(i);
- sum[c-'a']++;
- if(sum[c-'a']>maxV)
- {
- maxV=sum[c-'a'];
- res=c;
- }
- }
- System.out.println(res);
- System.out.println(maxV);
- }
- }
複製代碼 406- import java.util.Scanner;
- public class JAVA
- {
- public static void main(String[] args)
- {
- String str1="QAZWSXEDCRFVTGBYHNUJMIKOLP";
- String str2="WSXEDCRFVTGBYHNUJMIKMOLPLP";
- Scanner s=new Scanner(System.in);
- String str=s.nextLine();
- int len=str.length();
- for(int i=0; i<len; i++)
- {
- char c=str.charAt(i);
- if(c>='A' && c<='Z')
- {
- int index=str1.indexOf(c);
- System.out.print(str2.charAt(index));
- }
- else
- {
- c-=32;
- int index=str1.indexOf(c);
- char res=str2.charAt(index);
- res+=32;
- System.out.print(res);
- }
- }
- }
- }
複製代碼 |