 <p>Do it with <code>Java.util.Scanner</code>. Thats a really basic thing in java. I recommend you to do some research :) Here is an easy tutorial on that: <a href="http://www.homeandlearn.co.uk/java/user_input.html" rel="nofollow">http://www.homeandlearn.co.uk/java/user_input.html</a></p> <p>here an answere anyway:</p> <pre><code>public static void main(String[] args){ Scanner user_input = new Scanner( System.in ); String anInputString; anInputString = user_input.next( ); if (anInputString.equals("1 11")){ System.out.println("4") } if (anInputString.equals("11 111"){ System.out.println("34") } } </code></pre> <p>edit: </p> <p>if you want to achieve an output of "4" while your input lies between "1" and "11". Or "34" if its between "10" and "112" you should try this:</p> <pre><code> public static void main(String[] args){ Scanner user_input = new Scanner( System.in ); int anInputInt; anInputInt = user_input.nextInt( ); if (0 &lt; anInputInt &amp;&amp; anInputInt &lt; 11 ){ //if input is (1-10) System.out.println("4") } if (11 &lt;= anInputInt &amp;&amp; anInputInt &lt;= 111){ //if input is (11-111) System.out.println("34") } } </code></pre> <p>Anyway you should edit your question :D I think many people are happy to help you, but just cant understand your question at all 0.0</p> <p><strong>finally after I understood what you really want to do:</strong></p> <pre><code> public static void main(String[] args){ Scanner user_input = new Scanner( System.in ); int anInputInt; anInputInt = user_input.nextInt( ); if(anInputString &lt; 0){ anInputString = anInputstring*(-1); } int oneCount = 0; //gets all numbers in your specified range //if you want to start at number "xx" change the value of aNumberInRange likewise for (int aNumberInRange = 0; aNumberInRange &lt; anInputInt; aNumberInRange++){ String str = String.valueOf(aNumberInRange); //iterates through every character of an aNumberInRange and counts if a "1" occurs for(int i = 0; i &lt; str.length(); i++){ char c = str.charAt(i); if (c == 1){ oneCount++ } } } system.out.println(oneCount); } </code></pre> <p><strong>For whoever reads this solution. The client wanted to count all the occurences of the number "1" in a specified range. This should also work with negative Numbers</strong></p>