Java Assignment-I
Java Assignment-I
Email: [email protected]
JAVA PROGRAMMING
[ASSIGNMENT 1]
Q1. Write the Java code to fill and print a two dimensional array in following
format.
Elements are filled in spiral manner.
1
2
3
4
12 13 14
5
11 16 15
6
10
9
8
7
Q2. Write Java program to check whether two strings are anagrams or not, string
is assumed to consist of alphabets only. Two words are said to be anagrams
of each other if the letters from one word can be rearranged to form the other
word. From the above definition it is clear that two strings are anagrams if all
characters in both strings occur same number of times. For example "abc"
and "cab" are anagram strings, here every character 'a', 'b' and 'c' occur only
one time in both strings. Our algorithm tries to find how many times
characters appear in the strings and then comparing their corresponding
counts.
Q3. Write down function for the following problem:
Given three ints, a b c, return true if they are in strict increasing order, such
as 2 5 11, or 5 6 7, but not 6 5 7 or 5 5 7. However, with the exception that if
"equalOk" is true, equality is allowed, such as 5 5 7 or 5 5 5
public boolean inOrderEqual(int a, int b, int c, boolean equalOk) {
}
Q4. We want to make a row of bricks that is goal inches long. We have a number
of small bricks (1 inch each) and big bricks (5 inches each). Return true if it
is possible to make the goal by choosing from the given bricks. This is a little
harder than it looks and can be done without any loops.
public boolean makeBricks(int small, int big, int goal) {
}
Q5. Explain the followings:
a.
b.
c.
d.
e.