Write the two methods main and display.

Assignment Help JAVA Programming
Reference no: EM13940915

Implement your solution using one class. In your class, provide two methods - main and display.

main method:

Your main method should:

· Declare int number = 128;
· Include a while loop that loops while number is >= -128.
· Call the display method, which prints the value of its passed-in number parameter.
· If number is greater than zero, use the >>= operator to do one arithmetic-right shift.
· If number equals zero, use the ~ operator to complement it.
· If number is less than zero, use the <<= operator to do one left shift.
· After the while loop, ask the user to input any number, and call the display method to print that number.

display(number) method:

Write the display(number) method like this:

· Receive a number parameter.
· Print number's value and a tab. (t is tab in java)
· Assign to a local variable named mask the value 1 shifted left 31 times. This puts a 1 in bit 31 and zeros in all other bits.
· Use a for loop to step through all 32 bits, doing the following in each step:
o Use a conditional operator whose condition is (mask & number != 0) to print either 1 or 0.
o After every fourth bit, print a single space to make the output readable.

Sample Session:

Decimal Binary

128 0000 0000 0000 0000 0000 0000 1000 0000
64 0000 0000 0000 0000 0000 0000 0100 0000
32 0000 0000 0000 0000 0000 0000 0010 0000
16 0000 0000 0000 0000 0000 0000 0001 0000
8 0000 0000 0000 0000 0000 0000 0000 1000
4 0000 0000 0000 0000 0000 0000 0000 0100
2 0000 0000 0000 0000 0000 0000 0000 0010
1 0000 0000 0000 0000 0000 0000 0000 0001
0 0000 0000 0000 0000 0000 0000 0000 0000
-1 1111 1111 1111 1111 1111 1111 1111 1111
-2 1111 1111 1111 1111 1111 1111 1111 1110
-4 1111 1111 1111 1111 1111 1111 1111 1100
-8 1111 1111 1111 1111 1111 1111 1111 1000
-16 1111 1111 1111 1111 1111 1111 1111 0000
-32 1111 1111 1111 1111 1111 1111 1110 0000
-64 1111 1111 1111 1111 1111 1111 1100 0000
-128 1111 1111 1111 1111 1111 1111 1000 0000

Enter any integer: 127

127 0000 0000 0000 0000 0000 0000 0111 1111

Reference no: EM13940915

Questions Cloud

Determine the periodic time of the resulting shm : Determine the periodic time of the resulting SHM, the maximum velocity of the mass and (c) the maximum acceleration of the mass.
Choose a production plan that maximizes contribution : Kaplan Computers manufactures high end computer systems for the graphics design industry. At the present time, the company makes three computers with the following characteristics, Choose a production plan that maximizes contribution
Developing and revamping the juvenile justice system : Describing the juveniles of today and detailing how changes will address the challenges of juvenile delinquency today and make improvements to the current system.
Discuss whether gregs graphics liquidity is adequate : Explain how Greg's Graphics has financed the increase in assets. Discuss whether Greg's Graphics' liquidity is adequate. Explain why interest expense is growing.
Write the two methods main and display. : Implement your solution using one class. In your class, provide two methods - main and display.
Identify logistics management strategies : After reading material about John Lewis case, prepare a 3000-3500 word report ( executive summary, table of contents body, conclusions and recommendations) analysing the issues in the case, and identify logistics management strategies that enable ..
What would the price be if the company expected : What would the price be if the company expected a volume of 120,000 units and used a markup of 50%?
What type of special issue do juveniles face in adult prison : What types of special issues do juveniles face in adult prison? Do you agree that juveniles should be tried as adults for certain crimes? Be sure to support your argument with research and examples.
Marketing factors influencing decision making : A study into the marketing factors influencing that persuade the decision making of Chinese student

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create your listarray class

Create your ListArray class that is functionally similar to the formal Java ArrayList Utility class. here are the requirements

  Explain java stack and heap

I am posting the questions as reference, but I am requesting information about how to do these types of questions generally, not to have them done for me.

  If the number on two of the players'' four cards

If the number on two of the players' four cards is the same and the number on the remaining two cards is also the same yet the number on all four cards in not the same then the player gets their bet back and in addition wins 22 chips for each chip th..

  Develop an application that counts the number of words

Develop an application that counts the number of words, number of characters with spaces and without spaced

  Only allow the heroname as a parameter for the constructor

Only allow the heroName as a parameter for the constructor - Use the same code for defining the numberOfHeroes and the numberOfLifeChances

  Java coding if-else while loop

Code a while loop that keeps printing "You are a DEDICATED student!" as long as the user enters an attendance rate of 90% or greater. Assume the loop-control variable, attendance, is already declared along with input for the Scanner class. The w..

  It inherits the functionality of super class

It inherits the functionality of super class Package and contains an additional data member representing an additional fee per ounce charged for overnight-delivery service.

  Write a program that simulates a simple calculator

Write a program that simulates a simple calculator. It reads two integers and a character. If the character is a +, the sum is printed; if it is a -, the difference is printed; if it is a *, the product is printed; if it is a /, the quotient is pr..

  Design and implementation of a hangman game

Design and Implementation of a Hangman game

  Write a program that draws a picture of a house

Write a program that draws a picture of a house. It could be as simple as the accompanying figure, or if you like, make it more elaborate

  Javascript validation - cgi program

CGI mailer script form-mail.pl to your server's cgi-bin directory, and change the permissions on the script to make it executable - BMIS 310

  Describe the usefulness of the jframe class

What is a JFrame? Describe the usefulness of the JFrame class

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd