PAT L1-017 到底有多二 (15 分)

**

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

**

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner (System.in);
		String str =sc.nextLine();
		double a=1;
		double b=0;
		int c=1;
		int len =str.length();
		
		if(str.substring(0,1).equals("-")) {
			a= 1.5;
			len--;
		}
		for(int i=0;i<str.length();i++) {
			if(str.substring(i,i+1).equals("2")) {
				b++;
			}
		}
		if(Integer.parseInt((str.substring(str.length()-1)))%2==0) {
			
			c=2;
		}
		double end =b/len*a*c*100;
		
		
		System.out.printf("%.2f",end);
		System.out.println("%");
		
	}
}

猜你喜欢

转载自blog.csdn.net/Wdeadbug/article/details/90082290