Write a Java program that creates an array data of size 8, representing a binary number of 8 bits. The user must fillenter the clements of this array only by inputting 0 or 1. If the user enters any different number, the program must stop and display "Invalid data" message. If all entered digits are valid binary digits, the program must calculate and output the special decimal number represented by this binary number as shown in the below example: Ir the array data is 1 Result 1 X 20 + 0X 2 + 1 X 22 + 1X 2+ 0 X 21+ 0 X 2 + 0X 2 + 0 X 2 Result= 主 0. 4. 土 8. 0. 圭 0. 13 Then the result is calculated by ultiplying the value of the data array at each index with the result of 2 then adding all dhe answers. (shown in the ahove example) Sample run1: H«

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Write a Java program that creates an array data of size 8, representing a binary number of 8 bits.
The user must G/enter the elements of this array only by inputting 0 or 1, If the user enters any different
number, the program must stop and display "Invalid data" message.
If all entered digits are valid binary digits, the program must calculate and output the special decimal
number represented by this binary number as shown in the below example:
I the array data is
0 X 2 +
Result = 1 X 2 +
Result =
0 X 2 +
1 X 22 +
1X 2 +
0X 2 +
0X 2 +
0 X 2
0.
主
41
8.
0.
13
Then the result is calculated by niultiplying the value of the data aray at cach index with the result of 2
Ihen adding all dhe answers. (shown in the ahove example)
Sample run1:
Enter ihe
Transcribed Image Text:Write a Java program that creates an array data of size 8, representing a binary number of 8 bits. The user must G/enter the elements of this array only by inputting 0 or 1, If the user enters any different number, the program must stop and display "Invalid data" message. If all entered digits are valid binary digits, the program must calculate and output the special decimal number represented by this binary number as shown in the below example: I the array data is 0 X 2 + Result = 1 X 2 + Result = 0 X 2 + 1 X 22 + 1X 2 + 0X 2 + 0X 2 + 0 X 2 0. 主 41 8. 0. 13 Then the result is calculated by niultiplying the value of the data aray at cach index with the result of 2 Ihen adding all dhe answers. (shown in the ahove example) Sample run1: Enter ihe
Sample runl:
Enter the digits consisting of (0s or 1s): 2 5 4 1.3 2 5 7
Invalid data
Sample run2:
Enter the digits consisting of (0s or 1s): 11110 00 2
Invalid data
Sample run3:
Enter the digits consisting of (0s or 1s): 1 1 110 000
The number in decimal is 15
Sample run4:
Enter the digics consistirg of (0s or ls): 1 011:000 0
The number in decLmal is 13
Transcribed Image Text:Sample runl: Enter the digits consisting of (0s or 1s): 2 5 4 1.3 2 5 7 Invalid data Sample run2: Enter the digits consisting of (0s or 1s): 11110 00 2 Invalid data Sample run3: Enter the digits consisting of (0s or 1s): 1 1 110 000 The number in decimal is 15 Sample run4: Enter the digics consistirg of (0s or ls): 1 011:000 0 The number in decLmal is 13
Expert Solution
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY