输入样例:
-13142223336
输出样例:
81.82%
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str=scanner.next();
char[] c=str.toCharArray();
int count =0;
double res;
for(int i=0;i<c.length;i++) {
if(c[i]=='2') {
count++;
}
}
if(c[0]=='-') {
if(c[str.length()-1]%2==0) {
res=1.0*count/(c.length-1)*100*1.5*2;
System.out.printf("%.2f",res);
System.out.print("%");
}else {
res=1.0*count/(c.length-1)*100*1.5;
System.out.printf("%.2f",res);
System.out.print("%");
}
}else {
if(c[str.length()-1]%2==0) {
res=1.0*count/c.length*100*2;
System.out.printf("%.2f",res);
System.out.print("%");
}else {
res=1.0*count/c.length*100;
System.out.printf("%.2f",res);
System.out.print("%");
}
}
}
}