L1-017 到底有多二 (15 分) java解题

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4     public static void main(String args[]){
 5              double sum=0;
 6              double bei=1;
 7              int len;
 8              int count=0;
 9         String str=null;
10         Scanner in=new Scanner(System.in);
11         str=in.next();
12         len=str.length();
13         if (str.charAt(0)=='-'){
14             len=str.length()-1;
15             bei=1.5;
16         }
17         for (int i=0;i<str.length();i++){
18             if (str.charAt(i)=='2'){
19                 count++;
20             }
21         }
22         int bei2=1;
23         if (Integer.parseInt(str.charAt(str.length()-1)+"")%2==0){
24             bei2=2;
25         }
26         sum=((double) count/len)*bei*bei2*100;
27         System.out.printf("%.2f%s",sum,"%");
28     }
29 }

 

posted @ 2021-04-06 09:57  贾祥啊  阅读(233)  评论(0)    收藏  举报