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

  Write a java program that uses the elapsed time

Write a Java program that uses the elapsed time for an event in second and then outputs the elapsed time in hours, minutes and seconds. (For case, if the desired time is 9630 seconds, then the output is 2: 40: 30)

  Discuss how using arrays changes the way

Discuss how using arrays changes the way that your code is organized.

  Write an interface for a bagadt that implements iterable

Write an interface for a BagADT that implements the Iterable interface. Include javadoc comments that will generate specifications for the BagADT so that someone who wants to implement this interface will know what each method does.

  Write code that prompts the user to enter a string

Write code that prompts the user to enter a string containing ONLY a series of digits, then complete all of the following operations:

  Write a method insert at that takes an array of integers

Write a method, insertAt, that takes four parameters: an array of integers; the length of the array; an integer, say, insertItem; and an integer, say, index

  When are stubs & skeletons created for my ejb components

When are stubs & skeletons created for my EJB components? is it at development time, deployment time or run time?

  Write a test application named simpledatetest

Write a test application named SimpleDateTest that demonstrates class SimpleDate's capabilities

  Specifications of object instance variables and behaviors

Write simple, accurate object-oriented programs using primitive data types, variables, data structures, and object-oriented principles and implement classes that meet the given specifications of object instance variables and behaviors

  What are the three types of errors

What are the three types of errors that you can encounter in a Java program? Describe them, and explain how you would minimize the errors

  Write a class encapsulating the concept of student

Prepare a client class to test all the methods in your class. Make sure to add comments. Comments should be included in the program to explain your calculations and program.

  Write the classic arcade game of breakout

For each instance variable in your program, explain why you chose to make it an instance variable rather than a local variable - How did you test whether the game would end correctly in this second case? Did you make any changes to the code when test..

  Determine the precise big-oh values

Determine the precise Big-Oh values for each of the following code samples, based on the number of statement executions - Remember to consider each statement in compound statements separately.

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