java - Changing binary to decimal using created constants (not parseINT() ) and declaring and initializing each of the 8 bits of the number -


assignment

i have been working on forever now. required create constants declare , initiate each multiplying each it's place value (128,64,32,16,8,4,2,1)

i know integer.parseint(binary....) job cannot use it.

followed have far, on right track? know need each of separated user input values , have them multiplied place values added create decimal life of me cannot figure out how through loop or defining each variable

import java.util.scanner; import java.util.arrays; import java.util.list; import java.util.arraylist; import java.lang.integer; import javax.swing.jcombobox;  public class binary {  public static void main(string [] args) {     scanner keyboard = new scanner (system.in);     system.out.println("enter binary number please");     integer[] digits = getdigits(keyboard.nextint());        system.out.println(arrays.tostring(digits));  }//end bracket method main      public static integer[] getdigits(int num)     {         list <integer> digits = new arraylist <integer>();         collectdigits(num, digits);         return digits.toarray(new integer[]{});      }//end bracket method integer      private static void collectdigits(int num, list <integer> digits)     {         if(num / 10 > 0)        {             collectdigits(num / 10, digits);          }//end method collectdigits          digits.add(num % 10);      }  } 

i wanting separate each character of user input binary can have them multiplied place value, each product added create sum displayed user via system.out.println()

you importing wrong list type. change line:

import java.awt.list; 

to:

import java.util.list; 

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -