-
Notifications
You must be signed in to change notification settings - Fork 3
Assignment 1
- Your assignment includes three main classes:
- SumDiv.java
- Fermat.java
- Str.java
- Please submit the files no later than 16/03/2021 at 23:59.
- Algorithm efficiency will not be checked in this assignment.
- Reminder: Follow the Submission Instructions.
Write the class
public class SumDiv
Which receives 3 positive Integers 'a,b,c' as arguments and prints out the numbers between 1 and 'a' (including “a” itself) that is divisible by b
or c
. and the sum of all these numbers.
Example:
Input:6 3 4 .
Output:
3
4
6
13
If the arguments are invalid or there less or more than 3 arguments, the program should print “Invalid input”.
Please notice:
- You can assume the inputs will be numbers.
Write the class:
public class Fermat
which receives 2 positive Integers as arguments: n, range
The program should print all “a,b,c” for which the Pythagorean equation a^n + b^n = c^n is respected, s.t a
, b
and c
are between 1 and range (the second argument).
If no Pythagorean equation is found, print "no"
If the input has less than 2 values or if one of the values is not positive, the program must print “Invalid input”.
Please notice:
- You can assume the inputs will be numbers.
Examples: Input: 2 20.
Output:
3,4,5
5,12,13
6,8,10
8,15,17
9,12,15
Input: 3 20
Output: no
Write the class
public class Str
which receives two strings as arguments: query
and sequence
The sequence is a list of words separated by “_” and the query is any string.
The program should print two groups of words:
- The words in the sequence that start with the query (case sensitive)
- All words in the sequence that include the query (case sensitive)
Each group of words should be printed in the order they appear in the original sequence. If the input is not valid, the program should print out: Invalid input
Examples:
Input:
at i_am_good_at_maths_I_am_not_so_good_at_biology
Output:
at
at
maths
Input:
a We_play_soccer_and_basketball_every_Saturday
Output:
and
play
basketball
Saturday
input:
an We_play_soccer_and_basketball_every_Saturday
Output:
and
Helpful tips:
- Inside your main function, you receive the command line arguments as an array of Strings: public static void main(String[] args)
- Check string length - str.length()
- Check the array size - arr.length
- Get element from array by index - arr.index
- Get char from string by index - str.charAt(index)
build.xml file
Download our provided build.xml and put it under the main directory of your assignment (in the same directory where you have a src subdirectory).
Running Your Tasks
In order to compile and run your project, open the command prompt, navigate to the assignment directory, and type the desired ant
commands:
>> ant compile
>> ant -Dargs="at i_am_good_at_maths_I_am_not_so_good_at_biology" run3
The last command will run target run3 (corresponding to "Task 3"), and pass in
"at i_am_good_at_maths_I_am_not_so_good_at_biology" as command line arguments.