└── Hello.java /Hello.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Hello { 3 | public static String removeDigits(String Nu){ 4 | String ans=""; 5 | for(char N:Nu.toCharArray()){ 6 | if(N=='1'||N=='0'){ 7 | ans+=N; 8 | } 9 | } 10 | return ans;//returns zero and ones only 11 | } 12 | public static long decimalValue(String N){ 13 | if(N.length()<=0&&N.length()>31) return 0; 14 | //int num=Integer.parseInt(N); 15 | long s=0; 16 | // int poi=0; 17 | // while(num>0){ 18 | // int r=(int)num%10; 19 | // s=s+((int)Math.pow(2,poi)*r); 20 | // poi++; 21 | // num/=10; 22 | // } 23 | int l=N.length()-1; 24 | for(char i : N.toCharArray()){ 25 | int nu=Integer.parseInt(String.valueOf(i)); 26 | s+=(long)Math.pow(2,l--)*nu; 27 | } 28 | return s;//returns the equivalent decimal value 29 | } 30 | public static void main(String[] args) { 31 | //Remove digits-Except 0's and 1's and print the decimal value 32 | Scanner sc=new Scanner(System.in); 33 | String N=sc.next(); 34 | String numExcept=removeDigits(N); 35 | if(numExcept.equals("")){ 36 | System.out.print("-1"); 37 | return; 38 | } 39 | long val=decimalValue(numExcept); 40 | System.out.print((val<=0)?"-1":val); 41 | } 42 | } 43 | --------------------------------------------------------------------------------