answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
tatiyna
2 years ago
11

(NumberFormatException)Write the bin2Dec(String binaryString) method to convert a binary string into a decimal number. Implement

the bin2Dec method to throw a NumberFormatException if the string is not a binary string. Write a test program that prompts the user to enter a binary number as a string and displays decimal equivalent of the string. If the method throws an exception, display "Not a binary number".Sample Run 1Enter a binary number: 1015Sample Run 2Enter a binary number: 41Not a binary number: 41Class Name: Exercise12_07
Computers and Technology
1 answer:
tresset_1 [31]2 years ago
5 0

The following program will be used that prompts the user to enter a binary number as a string and displays decimal equivalent of the string.

<u>Explanation:</u>

NumberFormat.java

import java.util.Scanner;

public class NumberFormat{

public static void main(String[] args) {

      Scanner scan = new Scanner(System.in);

      try{

      System.out.println("Enter a binary string:");

      String s = scan.next();

      int integerValue = bin2Dec(Integer.parseInt(s));

      System.out.println("The decimal value of "+s+" is "+integerValue);

      }

      catch(NumberFormatException e){

          System.out.println(e);

      }

  }  

  public static int bin2Dec(int binaryNumber) throws NumberFormatException{

  int decimal = 0;

  int p = 0;

  try{

  while(true){

  if(binaryNumber == 0){

  break;

  } else {

  int temp = binaryNumber%10;

  decimal += temp*Math.pow(2, p);

  binaryNumber = binaryNumber/10;

  p++;

  }

  }

  }

  catch(NumberFormatException e){

      throw new NumberFormatException("Invalid binary number");

  }

  return decimal;

  }

}

Output:

Enter a binary string:

1011000101

The decimal value of 1011000101 is 709

You might be interested in
What is the Gain (dB) of a transmission if the Maximum Data Rate is 1 Gbps and the Bandwidth =7000 MHz? Group of answer choices
denpristay [2]

Answer:

15.420 dB

Explanation:

the Gain (dB) of a transmission if the Maximum Data Rate is 1 Gbps and the Bandwidth =7000 MHz is 15.420 dB.

3 0
2 years ago
5.11 Of these two types of programs:a. I/O-boundb. CPU-boundwhich is more likely to have voluntary context switches, and which i
Leno4ka [110]

Answer:

The answer is "both voluntary and non-voluntary context switch".

Explanation:

The description to this question can be described as follows:

Whenever processing requires resource for participant contextual switch, it is used if it is more in the situation of I/O tied. In which semi-voluntary background change can be used when time slice ends or even when processes of greater priority enter.

  • In option a, It requires voluntary context switches in I /O bound.
  • In option b, it requires a non-voluntary context switch for CPU bound.
7 0
2 years ago
A customer wants to increase his storage capacity by 25gb
Tom [10]

The answer is "SSD-25GB", and its further calculation can be defined as follows:

  • The <u><em>current generation of computer storage devices</em></u> is a hard drive (SSD).
  • It uses a flash memory that is substantially faster than a conventional mechanical disc.
  • The user does not require Storage or GPU, Video Card cannot be used.
  • RAM is a memory volatile that cannot be utilized as storage media.
  • SSD is better than magnetic HDD in terms of speed and performance.
  • SSD has become substantially quicker than USB 3.0.

That's why the answer is "SSD-25GB".

Learn more:

brainly.com/question/14411313

7 0
1 year ago
To erase an entire entry in a cell and then reenter the data from the beginning, press the ____ key. alt esc ctrl tab
Daniel [21]
To erase an entry in a cell and then reenter the data from the beginning press the esc key. Hope that helps!
8 0
2 years ago
Which statement below correctly differentiates between frames and bits? Frames have more information in them than bits. Frames a
9966 [12]
<span>Frames have more information in them than bits.
</span>
<span>Frames are made up of bits but not vice versa.


A bit (BInary digiT) is the basic unit of digital. It can be 0 (logical false, off) or 1 (not logical false - true, on). Four bits are in a nybble, which can have a value of 0 - 15, eight bits are in a byte which can have a value of 0 - 255. Words vary in size, they consist of multiple bytes and are generally correlated with the system's data bus/processor data width (a 64 bit system has an 8 byte word).
</span>
5 0
2 years ago
Read 2 more answers
Other questions:
  • Which of the following statements does not contain an error?
    13·1 answer
  • Mary can view the thumbnails of her presentation slides when she is creating the slides. Which element of the program’s interfac
    5·2 answers
  • The tuna marketers' task in the "tunathewonderfish.com" website and related campaign was to ________.
    15·1 answer
  • Write a static method, getBigWords, that gets a single String parameter and returns an array whose elements are the words in the
    15·1 answer
  • Suppose a host has a 1-MB file that is to be sent to another host. The file takes 1 second of CPU time to compress 50%, or 2 sec
    12·1 answer
  • "online privacy alliance (opa) is an organization of companies dedicated to protecting online privacy. members of opa agree to c
    15·1 answer
  • Discussion Question 10: A bank in California has 13 branches spread throughout northern California , each with its own minicompu
    13·1 answer
  • Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "To
    9·1 answer
  • How to code 2.9.5: Four colored triangles {Code HS}
    10·1 answer
  • 2. BIOS is contained in ROM and not in RAM. Can you guess why?​
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!