Write a code fragment that puts the binary representation of a positive integer n into a String variable s. Solution. Java has a built-in method Integer. To Binary String(n) for this job, but the...


Write a code fragment that puts the binary representation of a positive integer n into a String variable s.


Solution. Java has a built-in method Integer. To Binary String(n) for this job, but the point of the exercise is to see how such a method might be implemented. Working from Program 1.3.7, we get the solution


A simpler option is to work from right to left:


Both of these methods are worthy of careful study.


Program 1.3.7

Nov 13, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here