CSC 220 – Lab 5

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (3 votes)

Java programs:
1. Bits. Write a program Bits.java that takes a command-line argument N and uses a
while loop to compute the number of times you need to divide N by 2 until it is
strictly less than 1. Print out an error message if the integer N is negative.
% java Bits 0 % java Bits 8
0 4
% java Bits 1 % java Bits 16
1 5
% java Bits 2 % java Bits 1000
2 10
% java Bits 4 % java Bits -23
3 Illegal input
2. Design and implement an application named Swap.java that reads a string and two
index values from the user, then swaps the characters with the specified index values,
and save the resulting string in a variable. The program should have an input
verification loop ensuring that the specified index values are within range, and a loop
that asks users if they want to run the program again.
Compiling and running Java programs (reminder):
1. Compile your programs using the command javac filename
For example: javac myProgram.java
If you receive errors during the compilation phase, re-edit the source code file and
attempt to correct them.
2. Once a file successfully compiles, execute it using the java program.
For example: java MyProgram
What to turn in:
1. JAR all your files, including *.java and *.class files into a file called
Lab5.jar. When you’re done, upload the JAR file to Canvas, under category
Lab5.
2. If you do not complete the assignment before the end of the lab, you have until
the deadline to complete the assignment and have your Jar file uploaded to
Canvas. Canvas time rules! No extensions.
Hints:
Your work should be saved in a directory called Lab5 that you create in directory
CSC220.