title: How to make a Java program that takes two types of arguments?
body: <p>so I want to have my program able to take two arguments: the first one is a text file path and the second one is an integer represents how many lines I want to see.</p>
  
  <p>Right now, my code can work with the text file path argument but I can't get to the second method I made for the integer argument.</p>
  
  <p>For example, I try to run my program like this:</p>
  
  <blockquote>
    <p>run Read test.txt 3</p>
  </blockquote>
  
  <p>And it prints everything in the text file instead of 3 lines which I want it to be.</p>
  
  <p>Any help would be appreciated!</p>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  
  public class Read{
    public static void main(String[] args) throws FileNotFoundException{
      String in = new String(args[0]);
      String input = in;
      if (Character.isDigit(in.charAt(in.length() - 1))){
        hasNumInput(input);
      }else onlyStrInput(input);
    }
  
    public static void onlyStrInput(String filename) throws FileNotFoundException{
      File file = new File(filename);
      Scanner inFile = new Scanner(file);
      HashMap&lt;String, Integer&gt; map = new HashMap&lt;&gt;();
      String input = "";
      while (inFile.hasNext()){
        input = inFile.next();
        if (!map.containsKey(input)) map.put(input,1);
        else map.put(input, map.get(input) + 1);
      }
  
      int index = 1;
      while (!map.isEmpty()) {
        int max = 0;
        String maxP = "";
        for (Map.Entry&lt;String, Integer&gt; stringIntegerEntry : map.entrySet()) {
          Map.Entry entry = (Map.Entry) stringIntegerEntry;
          String key = (String) entry.getKey();
          Integer value = (Integer) entry.getValue();
          //if equals, alphabetically
          if (value == max) {
            if (maxP.compareTo(key) &gt; 0) {
              max = value;
              maxP = key;
            }
          }
          if (value &gt; max) {
            max = value;
            maxP = key;
          }
        }
        System.out.println(index++ + ". " + maxP + " = " + map.get(maxP));
        //pop out the max
        map.remove(maxP);
      }
    }
  
    public static void hasNumInput(String in) throws FileNotFoundException{
        int indexSpace = in.indexOf(" ");
        String strNum = in.substring(indexSpace + 1,in.length());
        int num = Integer.parseInt(strNum);
        String filename = in.substring(0,indexSpace);
  
        File file = new File(filename);
        Scanner inFile = new Scanner(file);
        HashMap&lt;String, Integer&gt; map = new HashMap&lt;&gt;();
        String input = "";
        while (inFile.hasNext()){
          input = inFile.next();
          if (!map.containsKey(input)) map.put(input,1);
          else map.put(input, map.get(input) + 1);
        }
  
        int index = 1;
        while (!map.isEmpty() &amp;&amp; num &gt; 0) {
          int max = 0;
          String maxP = "";
          for (Map.Entry&lt;String, Integer&gt; stringIntegerEntry : map.entrySet()) {
            Map.Entry entry = (Map.Entry) stringIntegerEntry;
            String key = (String) entry.getKey();
            Integer value = (Integer) entry.getValue();
            //if equals, alphabetically
            if (value == max) {
              if (maxP.compareTo(key) &gt; 0) {
                max = value;
                maxP = key;
              }
            }
            if (value &gt; max) {
              max = value;
              maxP = key;
            }
          }
          System.out.println(index++ + ". " + maxP + " = " + map.get(maxP));
          //pop out the max
          map.remove(maxP);
          num--;
        }
    }
  }
  </code></pre>