Question

Write: • Pseudocode. • Java program.

Write:

• Pseudocode.

• Java program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
PSEUDO CODE : 

Oro 1 BINARY = INPUT (ENTER INTEGER CONTAINING ONLY OS AND 1S) DECIMAL = 0 INDEX = 0 WHILE BINARY>0: DECIMAL = DECIMAL + POJAVA CODE : 

import java.text.DecimalFormat;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        //Prompt user for input
        Scanner obj = new Scanner(System.in);
        System.out.println("Enter number containing of 0s and 1s only");
        int binary = obj.nextInt();
        int decimal = 0,index=0;
        //Iterate through all digits
        while (binary>0){
            //Separate last number and multiply by weight
            decimal = decimal+(1<<index)*(binary%10);
            //Divide number by 10
            binary/=10;
            //Increment index
            index++;
        }
        System.out.println(decimal);
    }
}

OUTPUT :

Run: Main x C:\Program Files\Java\jdk-13\bin\java.exe -javaagent:C: Enter number containing of Os and 1s only 1101 13 Proc

Add a comment
Know the answer?
Add Answer to:
Write: • Pseudocode. • Java program.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT