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

  Fixing errors in a java program

You coded the following on line ten of the class MyApplet.java:

  Application for an animal-fur trimming service

Create an application for an animal-fur trimming service. Write the code for the application. Prompt the user to indicate how many animals. Display the total fee for one year. Be pleasant in your output as it will be expensive.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Write java program to receive input and displayed interest

Write a Java program that receive some input and displayed the interest. Format the number into 2 decimal places. Using loop is an advantage.

  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..

  Write program in java to calculate interest

Write a program in java to do the following : the following data is stored for each customer in the bank: account number,average balance and number of transaction for each customer it is required to calculate the interest earn

  Create and implement class called date to store month

Create and Implement the class called Date which has data members to store month (as a number), day, year, and name of month.

  Write a java applet for grade of gas in costco gas station

Write a java applet (not a java application program) for costco gas station. The applet will first ask you whether you are a costco customer, then the grade of gas you want to use.

  Describe how an eavesdropped can gain access

Describe how an eavesdropped can gain access to the remote server with a relatively modest number of guesses ( Hint:  The eavesdropped starts guessing after the original user has typed all but one character of the password.

  Client server chat system

Threading and GUI design using Java's network library, threading system, and swing user interlace libraries to implement a basic chat client and saver system. Thc system will allow multiple. remote users to send and receive messages across the net..

  Write a program that simulate n rolls of six-sided die

Write a program that simulate n rolls of six-sided die and displays the frequency of occurrence of each side and What is the most likely method signature of the "parseInt() - TNE60003

  Determine if strings are equal

Complete the recursive method match in the code below which will determine whether or not two strings match.

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