I tried using sc.hasNextLine();
Got the same following error
"
Exception in thread “main” java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:592)
at java.lang.Integer.parseInt(Integer.java:615)
at Main.main(Main.java:14) "
import java.util.*;
public class Main
{
public static HashMap<Integer,Long> map= new HashMap<Integer,Long>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine())
{
String s =sc.nextLine();
int n =Integer.parseInt(s);
System.out.println(maxDollars(n));
}
}
public static long maxDollars(int n)
{
if(n<12) return n;
if(map.containsKey(n)) return map.get(n);
long max=maxDollars(n/2)+maxDollars(n/3)+maxDollars(n/4);
map.put(n,max);
return max;
}
}