I am almost a complete beginner.
I need to write a program that asks user to input a binary number, verifies whether the number is in fact binary, and then count the number of 1's in the binary number.
So far I have this:
import java.util.Scanner;
import java.text.DecimalFormat;
public class BinaryWords
{
public static void main( String [] args )
{
int binaryNumber1;
int binaryNumber2;
int binaryNumber3;
int binaryNumber4;
int binaryNumber5;
int binaryNumber6;
int binaryNumber7;
int binaryNumber8;
int binaryNumber9;
int binaryNumber10;
int binaryNumberWhole = binaryNumber1 + binaryNumber2 + binaryNumber3
+ binaryNumber4 + binaryNumber5 + binaryNumber6 + binaryNumber7
+ binaryNumber8 + binaryNumber9 + binaryNumber10;
if 1<binaryNumber1<0
then final int SENTINEL = binaryNumber1;
System.out.println( "This program verifies a binary number"
+ "representing a word and then"
+ "counts how many 1's are in that number");
System.out.println("Please enter a binary number representing a word");
Not pretty, I know! I am confused as to how to read each binary number in the binary sequence and check for 0 or 1.
Any help would be greatly appreciated!
Aucun commentaire:
Enregistrer un commentaire