题目要求
题目分析
没错,就像下面代码那么二
示例代码
public class L1_017 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String input = sc.nextLine();
sc.close();
double count = 0;
for(int i = 0; i < input.length(); i++) {
char c = input.charAt(i);
if(c == '2') {
++count;
}
}
double two = 0;
if(input.charAt(0) != '-') {
two = count / input.length()*100;
}else {
two = (count / (input.length()-1))*1.5*100;
}
if(Integer.parseInt(input.substring(input.length()-1)) % 2 == 0) {
two = two * 2;
}
System.out.printf("%.2f",two);
System.out.println("%");
}
}