返回列表 發帖
本帖最後由 孫文康 於 2024-1-20 17:23 編輯

304
  1. import java.util.Scanner;
  2. public class JAVA{
  3.         static int compute(int date[])
  4.         {
  5.                 int sum=0;
  6.                 for(int i=0;i<6;i++)
  7.                         if(date[i]%3==0)
  8.                                 sum++;
  9.                 return sum;
  10.         }
  11.         public static void main(String[] args)
  12.         {
  13.                 int date[]=new int[6];
  14.                 Scanner s=new Scanner(System.in);
  15.                 for(int i=0;i<6;i++)
  16.                         date[i]=s.nextInt();
  17.                 System.out.println(compute(date));
  18.         }
  19. }
複製代碼
306
  1. import java.util.Scanner;
  2. public class JAVA
  3. {
  4.         static int compute(int n)
  5.         {
  6.                 if(n==1)
  7.                         return 1;
  8.                 else
  9.                         return n*compute(n-1);
  10.         }
  11.         public static void main(String[] args) {
  12.                 Scanner s=new Scanner (System.in);
  13.                 int n=s.nextInt();
  14.                 System.out.println(n+"!="+compute(n));
  15.         }

  16. }
複製代碼
310
  1. import java.util.Scanner;
  2. public class JAVA {
  3.         static int compute(int n)
  4.         {
  5.                 int total=0;
  6.                 for(int i=1; i<n; i++)
  7.                 {
  8.                         int sum=0;
  9.                         String str=String.valueOf(i);// int to string
  10.                         int len=str.length();//length() 得到字串長度
  11.                         for(int j=0; j<len; j++)
  12.                         {
  13.                                 int t=str.charAt(j)-'0';//將各個數字轉換為int
  14.                                 sum+=Math.pow(t, len);//並進行自身位數次方的動作
  15.                         }
  16.                         if(sum==i)//判斷是否為阿姆斯壯數
  17.                         {
  18.                                 System.out.println(i);
  19.                                 total+=i;
  20.                         }
  21.                 }
  22.                 return total;
  23.         }
  24.         public static void main(String[] args) {
  25.                 Scanner s=new Scanner(System.in);
  26.                 int n=s.nextInt();
  27.                 System.out.println(compute(n));
  28.         }
  29. }
複製代碼
404
  1. import java.util.Scanner;
  2. public class JAVA {
  3.         public static void main(String[] args) {
  4.                 int sum[]=new int[26];
  5.                 Scanner s=new Scanner(System.in);
  6.                 String str=s.nextLine();
  7.                 int len=str.length(),maxV=0;
  8.                 char res=0;
  9.                 for(int i=0;i<len;i++)
  10.                 {
  11.                         char c=str .charAt(i);
  12.                         sum[c-'a']++;
  13.                         if(sum[c-'a']>maxV)
  14.                         {
  15.                                 maxV=sum[c-'a'];
  16.                                 res=c;
  17.                         }
  18.                 }
  19.                 System.out.println(res);
  20.                 System.out.println(maxV);
  21.         }
  22. }
複製代碼
406
  1. import java.util.Scanner;
  2. public class JAVA
  3. {
  4.         public static void main(String[] args)
  5.         {
  6.                 String str1="QAZWSXEDCRFVTGBYHNUJMIKOLP";
  7.                 String str2="WSXEDCRFVTGBYHNUJMIKMOLPLP";
  8.                 Scanner s=new Scanner(System.in);
  9.                 String str=s.nextLine();
  10.                 int len=str.length();
  11.                 for(int i=0; i<len; i++)
  12.                 {
  13.                         char c=str.charAt(i);
  14.                         if(c>='A' && c<='Z')
  15.                         {
  16.                                 int index=str1.indexOf(c);
  17.                                 System.out.print(str2.charAt(index));
  18.                         }
  19.                         else
  20.                         {
  21.                                 c-=32;
  22.                                 int index=str1.indexOf(c);
  23.                                 char res=str2.charAt(index);
  24.                                 res+=32;
  25.                                 System.out.print(res);
  26.                         }
  27.                 }
  28.         }
  29. }
複製代碼

TOP

返回列表