0% found this document useful (0 votes)
5 views2 pages

Early Computing 4

Early Computing 4

Uploaded by

Reden Tomé
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Early Computing 4

Early Computing 4

Uploaded by

Reden Tomé
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ELEBIYO TOME, RUBEN. BSIT.

10/05/24

SANTOS, OLYN DARIANE

Source Code:

Import [Link];

// opens the class and declares the main method and scanner

Public class DecimalToBinaryCalculator {

Public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

// Starts asking for the decimal number unless the word “STOP”
is entered

For (;;) {

[Link](“Please enter a decimal number (insert


‘STOP’ to exit): “);

String userInput = [Link]();

If ([Link](“STOP”)) {

[Link](“Program terminated, thanks for using


^.^”);

Break; // Exit the loop

//excecutes the code that can have an exception, in that


case: e

Try {

Int decimalNumber = [Link](userInput);

String binaryNumber =
[Link](decimalNumber); // Converts the decimal
number to binary

[Link](“Decimal: “ + decimalNumber + “ =>


Binary: “ + binaryNumber);
// if we have an exception, that will handle it correctly

} catch (NumberFormatException e) {

[Link](“Invalid input! Please enter a valid


decimal number or ‘STOP’.”);

// Closes the scanner

[Link]();

//end of the class

PROOF SCREENSHOTS:

You might also like