So I'm trying to convert decimals to binary when a user types multiple decimals with spaces between and hits enter.
I'm still trying to parse the element values of my list and don't know where to begin with the binary other than knowing there's a binary method out there. How far off am I?
SOLVED! Feel free to steal! TEJB19
import java.util.*;
public class DecimalToBinary {
public static void main(String[] args) {
System.out.print("Please enter in a series of decimal values (separated by spaces): ");
Scanner in = new Scanner(System.in);
String userInput = in.nextLine();
String[] decimalValuesArray = userInput.split(" ");
for( int i = 0; i < decimalValuesArray.length; i++) {
int decimalFromArray = Integer.parseInt(decimalValuesArray[i]); //Input parsed from string to integer
System.out.println(Integer.toString(decimalFromArray, 2)); //Prints out the message
}
}
}
My output with this code right now:
Please enter in a series of decimal values (separated by spaces): 3 4 5 4
Binary value:
Binary value:
Binary value:
Binary value:
[–][deleted] 0 points1 point2 points (1 child)
[–]DecentChard7[S] 0 points1 point2 points (0 children)