LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 5 years have passed since last update.

codeIQ_7の数を数える

Posted at
count7.java
import java.io.*;
class Main{

    public static void main(String[] args) throws IOException{
        int int7Cnt;
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        String strStdIn = in.readLine();

        while(strStdIn!=null){
            int7Cnt = 0;//カウンタ初期化
           int intMax = Integer.parseInt(strStdIn);

           for(int i=7;i<=intMax;i++){
               String strI = String.valueOf(i);
                for(int j=0;j<strI.length();j++){
                    if(strI.trim().substring(j,j+1).equals("7")){
                        int7Cnt++;
                    }
                }
           }
            System.out.println(int7Cnt);
            strStdIn = in.readLine();
        }
    }
}
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up