Java Binary-to-Decimal Converter

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class BinaryConverter
{
public static void main(String[] args) throws IOException
{
// TODO Auto-generated method stub
System.out.println(“Please select one of the following options: “);
System.out.println(“1. Decimal to Binary: “);
System.out.println(“2. Binary to Decimal:”);
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
Integer input = Integer.parseInt(bf.readLine());
System.out.println(“———————————————“);
if (input == 1)
{
BufferedReader bf1 = new BufferedReader(new InputStreamReader(System.in));
String input1 = bf1.readLine();
Converter con = new Converter();
System.out.println(“Answer: ” + con.TransInputbin(input1));
System.out.println(“———————————————“);
}
else
if (input == 2)
{
BufferedReader bf2 = new BufferedReader(new InputStreamReader(System.in));
String input2 = bf2.readLine();
Converter con = new Converter();
System.out.println(“Answer: ” + con.setInput(input2));
System.out.println(“———————————————“);
}
}
}

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;
public class BinaryConverter { public static void main(String[] args) throws IOException  { // TODO Auto-generated method stub System.out.println(“Please select one of the following options: “); System.out.println(“1. Decimal to Binary: “); System.out.println(“2. Binary to Decimal:”); BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); Integer input = Integer.parseInt(bf.readLine()); System.out.println(“———————————————“); if (input == 1) { BufferedReader bf1 = new BufferedReader(new InputStreamReader(System.in)); String input1 = bf1.readLine(); Converter con = new Converter(); System.out.println(“Answer: ” + con.TransInputbin(input1)); System.out.println(“———————————————“); } else if (input == 2) { BufferedReader bf2 = new BufferedReader(new InputStreamReader(System.in)); String input2 = bf2.readLine(); Converter con = new Converter(); System.out.println(“Answer: ” + con.setInput(input2)); System.out.println(“———————————————“); } }}

Advertisements

One Comment on “Java Binary-to-Decimal Converter

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: