Java Write a program as follows: Prompt the user to enter a string containing a hexadecimal number. Use class Integer to parse the input to a base-10 integer variable and display it. Convert this base-10 variable to a string holding an equivalent number in binary. Print this binary equivalent. Use class Integer to convert the binary string back to base-10 and display it. SAMPLE OUTPUT Enter a string holding a hexadecimal integer less than 256  1a That hex number in base-10 is 26 As a binary number it's 11010 That binary number back to base-10 is 26

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

Java

Write a program as follows:

  • Prompt the user to enter a string containing a hexadecimal number.
  • Use class Integer to parse the input to a base-10 integer variable and display it.
  • Convert this base-10 variable to a string holding an equivalent number in binary.
  • Print this binary equivalent.
  • Use class Integer to convert the binary string back to base-10 and display it.

SAMPLE OUTPUT

Enter a string holding a hexadecimal integer less than 256 
1a
That hex number in base-10 is 26
As a binary number it's 11010
That binary number back to base-10 is 26

4. Write an executable program that has just a main method. In main:

  • create an instance of StringBuilder that initially holds an empty string.
  • append your first name to the string.
  • append your surname to the string.
  • display your name.
  • insert your middle initial where it should be and spaces as needed. If you don't have a middle name, fake it.
  • display your name with middle initial.
  • delete your initial and the space(s).
  • display your name in reverse order. 

SAMPLE OUTPUT

John Public
John Q Public
cilbuP nhoJ

Expert Solution
Step 1

Note: As per policy we are entitled to answer 1 question at a time.

Program Approach:

  • Import necessary package
  • Define main class
  • Defining the main method
  • Creating an object of the class
  • Ask the user to enter a string holding a hexadecimal integer less than 256
  • Reading values
  • Declaring integer variable n
  • Display the output
  • Declaring method hexaToDecimal
  • Defining string value
  • Declaring method binToDec
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning