DSA Programming Assignment-I
DSA Programming Assignment-I
Programming Assignment-I
(Java Primer)
1. Write a Java program that takes as input three integers, a, b, and c, from the Java console
and determines if they can be used in a correct arithmetic formula (in the given order), like
“a + b = c,” “a = b − c,” or “a ∗ b = c.”
2. Write a Java program that can take a positive integer greater than 2 as input and write out the
number of times one must repeatedly divide this number by 2 before getting a value less
than 2.
3. Write a Java program that outputs all possible strings formed by using the characters 'c',
'a', 'r', 'b', 'o', and 'n' exactly once.
4. Write a Java program that takes all the lines input to standard input and writes them to
standard output in reverse order. That is, each line is output in the correct order, but the
ordering of the lines is reversed.
5. Write a Java method, isOdd, that takes an int i and returns true if and only if i is odd. Your
method can't use the multiplication, modulus, or division operators, however.
6. Write a Java method for finding the smallest and largest numbers in an array of integers and
compare that to a java method that would do the same thing.
7. Write a Java method that takes an array of int values and determines if there is a pair of
distinct elements of the array whose product is odd.
8. Write a Java program that takes two arrays a and b of length n storing int values, and returns
the dot product of a and b. That is, it returns an array c of length n such that c[i] = a[i] · b[i],
for i = 0, . . . , n − 1.
9. Create a class Student with instance variables name, roll, mark and instance methods
setData(), display(). Write a Java program to create three objects of Student class to input
details of three different students and display the details. Enclose main() method inside
another class StudentDetails. (Use the setter method setData() to input details.)
10. Rewrite question 9 with instance method setData(String,int,double). Use the setter method
setData() to initialize members.
11. Create a class Point with instance variables x, y to represent co-ordinates of point and
instance method setPoint(). Write a Java program to find distance between two points using
a method findDistance(Point,Point).
12. Write a Java class Flower that has three instance variables of type String, int, and float,
which respectively represent the name of the flower, its number of petals, and price. Your
class must include a method that initializes each variable to an appropriate value, and your
class should include methods for setting the value of each type, and getting the value of each
type.
******************