Accepts a binary number from the user

Assignment Help JAVA Programming
Reference no: EM13163578

Write a Java test program that accepts a binary number from the user. You should store the binary number in a String. Your program should then use afor loop to sequence through every character in the String, counting the number of ones, zeros, and other characters. Your code should display the three counters after the loop terminates.

Here is a starter code;

import javax.swing.*;

// count the number of 1s, 0s, and other characters

public class BinaryDigitCounter

{

public static void main(String[] args)

{

String ui; // user input

int oneCount = 0, zeroCount =0, otherCount = 0;

ui = JOptionPane.showInputDialog(null, "Enter a binary number")

// check each character in the string

// add one to the appropriate counter

for(int i = 0; i < ui.length(); i++)

{

if ( ui.charAt(i) =='1' )

{

}

} // end for

} // end main

}

Reference no: EM13163578

Questions Cloud

Explain possible intermediate and the transition states : Draw the energy profile diagram to show the possible intermediate and the transition states.
Disk requests arrive at the disk driver : Disk requests arrive at the disk driver for cylinders, 45, 97,21,43,11,69,81,8,55,14,78,74, and 7. A seek takes 5 milliseconds per cylinder moved. Assume that the arm starts initially at cylinder 50 and was moving downward.
Create a script file for conversion of temperature : Create a script file for conversion of temperatures. Use the input function or menu function to allow the user to enter temperature scale of Fahrenheit, Celsius, Kelvin, or Rankine. If you are using the input function, tell the user to enter F for Fa..
Explain bromobutane and sodium azide in dmf : Consider the reaction that will take place between (S) -2-bromobutane and sodium azide in DMF. A) What is the product of this reaction (give proper stereochemistry of the product formed)
Accepts a binary number from the user : Write a Java test program that accepts a binary number from the user. You should store the binary number in a String. Your program should then use afor loop to sequence through every character in the String, counting the number of ones, zeros, and..
Program that read in from the key board a string : Write a complete C++ program that read in from the key board a string and convert all letters in the string to upper cases. You are not allowed to use toupper function.
State a certain reaction has an activation energy : A certain reaction has an activation energy of 27.03 kJ/mol. At what Kelvin temperature will the reaction proceed 3.00 times faster
Squares, triangles, circles and ellipses : write a program which will answer a pair of questions for squares, triangles, circles and ellipses. A square is defined by its lower left corner ( S L L x , S L L y ), and the length of one side  S W .
The strike predicate need not work : Define a predicate strike(X,Y,Z) that succeeds if and only if the list Z would be obtained if one were to remove all occurrences of element X from list Y. The strike predicate need not work well when Y is an unbound variable.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Uses a 2-d array to store the highest and lowest temperature

Write a program that uses a 2-D array to store the highest and lowest temperatures for each montjh of the year. The program should output the average high, average low, and highest and lowest temperatures of the year. Your program must consist of ..

  Write a method called printlevel

Write a method called printLevel that takes an integer n as a parameter and that prints the values at level n from left to right. The values should be printed one per line.

  Design a single class that expresses the commonality

Design a single class that expresses the commonality of these concepts.

  Implement a shopping cart class with user interface

project will be to implement a shopping cart class with user interface (UI) that contains main() in Net Beans. The UI class will be used to perform user input/output and to invoke the appropriate methods of shopping cart class. When your program star..

  Application that generates a quiz

Create an application that generates a quiz. Prompt for the user's first and last name, college major, and confidence in test taking (high, medium, or low). The quiz should contain at least five true/false questions about horticulture. When the user ..

  Java script program for song

Construct a JavaScript program that declares and prints an array that includes at least twenty of your favorite songs.

  Java project

Prompt the user for an int between lower and upper boundary.

  Java applet to find how much federal tax we need to pay

Write a java applet to determine how much federal tax we need to pay assuming the tax rate is 12%.  Ask the taxable income.

  Please write the code in java

Please write the code in java for  Recursion,  Sorting and Searching

  Java program use breadth-first search closest broadcast

Write the java program which will use breadth-first search (which you implement as part of your program) to determine the closest broadcast vertex for each vertex in graph.

  Write java program to read in sequence of hourly temperature

Write down Java program which reads in sequence of hourly temperature readings over 24-hour period using arrays. Your program must find and show maximum and minimum temperatures.

  Program should assign a seat in the first class

If a person enters 1, your program should assign a seat in the first class (rows 1 - 3). If a person enters 2, your program should assign a seat in business class (rows 4 - 7). If a person enters 3, your program should assign a seat in economy class ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd