CSCI 201: Intro to Programming (Java)
Assignment 3. Due: Tue, Oct 10
Please put your work in directory cs201 on your Linux account before 11:59pm of the day above.
- (25 points)
Write a Java application that asks for a positive integer from the keyboard
and determines whether it is a prime number or not. You program has to output
either "is a prime number" or "is not a prime number" depending on the
input number.
Recall that a number is a prime if it is not divisible by any number except
1 and itself.
Name the project Hw3_1
Solution
- (25 points)
Write a Java application that asks for an integer and returns its
factorization into prime factors including their powers. The prime factors
must appear in increasing order. For example if 120 ( = 2*2*2*3*5) in the
input number, then your program should output
120 = 2^3 * 3^1 * 5^1
The factors should appear in increasing order and should be separated
from each other by asterisks ( * ).
Hint: find the smallest prime factor and output it. Divide your number
by that factor and apply the same approach to the quotient. Stop when the
quotient is 1.
Name the project Hw3_2
Solution
- (25 points)
Design a Java program that computes GCD (Greatest Common Divisor) of several
positive integers, given as command-line parameters. For example, if the
given numbers are 24, 36, 16, 48 then to compute GCD(24, 36, 16, 48) you can
first compute GCD(24, 36) = 12, then GCD of the result and the next given
number, that is GCD(12, 16) = 4, and, finally, GCD of the obtained result and
the last number, i.e., GCD(4, 48) = 4. The obtaned number it the last step (4
in our example) is the answer.
Name the project Hw3_3
Solution
- (25 points)
Write a Java application ant asks for a string and outputs the number of
occurences of every letter in the string. For example, if the input string is
"introduction", your program should produce the following output:
i: 2
n: 2
t: 2
r: 1
o: 2
d: 1
u: 1
c: 1
Name the project Hw3_4
Solution