Skip to content

Commit fa3a573

Browse files
Merge pull request #320 from subhayudutta/new-user
BinaryDecimalConvertorApp
2 parents 007ab11 + eecc2d4 commit fa3a573

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

BinaryDecimalConverto/convertor.java

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.util.Scanner;
2+
3+
public class BinaryDecimalConverter {
4+
public static void main(String[] args) {
5+
Scanner scanner = new Scanner(System.in);
6+
7+
System.out.println("Binary to Decimal and Decimal to Binary Converter");
8+
System.out.print("Enter 1 to convert Binary to Decimal or 2 to convert Decimal to Binary: ");
9+
int choice = scanner.nextInt();
10+
11+
if (choice == 1) {
12+
System.out.print("Enter a binary number: ");
13+
String binaryInput = scanner.next();
14+
int decimalResult = binaryToDecimal(binaryInput);
15+
System.out.println("Decimal result: " + decimalResult);
16+
} else if (choice == 2) {
17+
System.out.print("Enter a decimal number: ");
18+
int decimalInput = scanner.nextInt();
19+
String binaryResult = decimalToBinary(decimalInput);
20+
System.out.println("Binary result: " + binaryResult);
21+
} else {
22+
System.out.println("Invalid choice. Please enter 1 for Binary to Decimal or 2 for Decimal to Binary.");
23+
}
24+
}
25+
26+
public static int binaryToDecimal(String binary) {
27+
return Integer.parseInt(binary, 2);
28+
}
29+
30+
public static String decimalToBinary(int decimal) {
31+
return Integer.toBinaryString(decimal);
32+
}
33+
}

BinaryDecimalConverto/readme.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Binary to Decimal and Decimal to Binary Converter
2+
3+
This is a simple Java program that allows you to convert between Binary and Decimal numbers.
4+
5+
## How to Use
6+
7+
1. Compile and run `BinaryDecimalConverter.java`.
8+
2. Choose option 1 to convert Binary to Decimal or option 2 to convert Decimal to Binary.
9+
3. Follow the on-screen instructions to enter the number for conversion.
10+
11+
## Features
12+
13+
- Converts Binary to Decimal and Decimal to Binary.
14+
- Simple command-line interface for ease of use.
15+
16+
## Technologies Used
17+
18+
- Java
19+
20+
Feel free to modify the code or integrate it into other Java applications as needed.

0 commit comments

Comments
 (0)