i am new in java programming, can someone help me create the code for it.thanks.

Recommended Answers

All 5 Replies

can someone help me create the code

We'll help you get your code to work when you post it.
First you need to describe what you are trying to do in your program.
The title doesn't really describe what the problem is.

This is the program that was given to me and I don't have idea how to do it. I hope someone could help me...

Create three (3) java program that:
1. Converts a binary number to decimal,
2. Converts a binary number to hexadecimal,
3. Converts a binary number to octal,

using a single dimensional array

Example Input/Output
1. Binary to decimal converter:

Enter binary number:

11100000 binary is equal to 224 decimal

Have you looked up the algorithm for converting a binary number to a decimal number?
You need that before you can write the program.

Assuming that you read the input: 11100000 as a String. You will create an int array with size the length of the input. Check the API of the String class. There are methods that return its length as well as each character of the String (charAt(index))
Loop the input, take each character convert it to a String, then to an int and put it into the array:

String s = "11100000";
for (int i=0;i<s.length();i++) {
  char ch = s.charAt(i);

Convert the ch to a String String s2 = ch+""; Then put that s2 into the int array.

Then you can apply the algorithm.

If you had the binary number '11100000', could you work out its decimal value yourself, with a pencil and a pad of paper? If you program a computer to do something similar, you will get a value stored in an 'int' variable, which you can print. (And it will, by default, print the decimal value.)

For the other two...
Ask yourself, "How many binary bits are in one hexadecimal digit?"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.