Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS570-Java_Projects
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bjv33
CS570-Java_Projects
Commits
7634c4e9
Commit
7634c4e9
authored
6 years ago
by
bjv33
Browse files
Options
Downloads
Patches
Plain Diff
Binary Representation -- Recursion
parent
3835ab05
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Binary_Representation.java
+51
-0
51 additions, 0 deletions
Binary_Representation.java
with
51 additions
and
0 deletions
Binary_Representation.java
0 → 100644
+
51
−
0
View file @
7634c4e9
// Program: Binary_Representation.java
// Purpose: Writes a recursive method that converts a number from its decimal representation to its binary representation.
// Author: Brian Vojtko
// Date: 10/24/2018
import
java.util.Scanner
;
public
class
Binary_Representation
{
public
static
void
binConv
(
int
number
)
{
if
(
number
>
0
)
{
binConv
(
number
/
2
);
System
.
out
.
print
(
number
%
2
);
}
}
public
static
void
main
(
String
[]
args
)
{
Scanner
input
=
new
Scanner
(
System
.
in
);
boolean
loop
=
true
;
while
(
loop
)
{
System
.
out
.
print
(
"Enter a positive integer or 0 to end: "
);
int
number
=
input
.
nextInt
();
while
(
number
<
0
)
{
System
.
out
.
println
(
"Error: You entered a negative value. Try again."
);
number
=
input
.
nextInt
();
continue
;
}
if
(
number
==
0
)
{
System
.
out
.
println
(
"Goodbye"
);
return
;
}
System
.
out
.
print
(
number
+
" in binary is "
);
binConv
(
number
);
if
(
number
>=
1
)
{
loop
=
true
;
System
.
out
.
println
(
""
);
}
else
{
loop
=
false
;
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment