赞
踩
加班回到寝室,再来刷一波水题!!!
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* 题意:如果一个数中 4和7 的个数为lucky number(每位数字仅仅是 4或7),则该数是nearly lucky number,问该数是不是nearly lucky number?
*
* @author TinyDolphin
* 2017/6/26 22:15.
*/
public class Main {
/**
* 判断该数是否是幸运数字(即仅仅包含4和7)
*/
public static boolean isLuckNum(int num) {
String str = num + "";
for (int index = 0; index < str.length(); index++) {
if (str.charAt(index) != '4' && str.charAt(index) != '7') {
return false;
}
}
return true;
}
public static void main(String[] args) throws IOException {
//StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
String inputNum; // 输入的数
int luckPosition; // 记录幸运位
while (in.hasNext()) {
inputNum = in.next();
luckPosition = 0;
char temp;
for (int index = 0; index < inputNum.length(); index++) {
temp = inputNum.charAt(index);
if (temp == '4' || temp == '7') {
luckPosition++;
}
}
out.println(isLuckNum(luckPosition) ? "YES" : "NO");
}
out.flush();
}
}
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。