# Task 01 - Java Basics

Task Objects:

- Writing, compiling and running Hello World program
- Using primitive data types and their literals
- Getting input from user of different primitive types
- Using escape sequences and format specifiers
- Using functions of Math for sin, cos, tan, ceil, and floor etc. and using Random class
- Using if/else and loops in Java

Programming is your core course, so I expect and suggest you to spend at least 2 hours a day on average. That means, you must spend arround 14 hours per week on OOP. It may seems difficult, but if you do it, InshaAllah you would be able to make complete software using Java GUI for basic business needs and learning Android programming would take just 1-2 months after this course.

____

1. Make a class HelloWorld.java and define main method in it. The method should get 2 integers from user and print sum on command line interface (CLI). After this task, you should be able to:

- Create and save HelloWorld.java file
- Declare and initialize variable of type int
- Compile and run it
- Get input from user using Scanner class
- Using System.out.println and System.out.printf functions

2. Make another class named MinMaxAverage.java, when its compiled and executed, its main method should take three double numbers from user and print minimum, maximum and average number on CLI.

______

Then update the program, such that, it get the start value from user and print table from start-value to end-value.

A leap year is one which is evenly divided by 4. But for century years, the year must also be evenly divided by 400. e.g. 1800 is divisible at 4, but not leap because its a century year and is not evenly divisible at 400. So you must also check whether the user entered year is century year or not to decide correctly. (optional : also add 2-3 lines multi-line comment in your program that explains why we need leap years and why Feb days are 29 in leap year. see http://www.mathsisfun.com/leap-years.html).

______

3. Take two integers from user i.e. table-number and ending-value. As output, show the table of user entered number up to ending-value. Your output must follow below format. I assume user entered: 3 and 6, the output should table of 3, printed up to 6.

1 x 3 = 3

2 x 3 = 6

3 x 3 = 9

4 x 3 = 12

5 x 3 = 15

6 x 3 = 18

1 x 3 = 3

2 x 3 = 6

3 x 3 = 9

4 x 3 = 12

5 x 3 = 15

6 x 3 = 18

Then update the program, such that, it get the start value from user and print table from start-value to end-value.

______________

4. Get an integer from that represent a year, it must be greater than 500, if less, ask again until valid number is entered (hint: use loop to remain asking until valid number is given). Your program should print, is the year is leap or not.

A leap year is one which is evenly divided by 4. But for century years, the year must also be evenly divided by 400. e.g. 1800 is divisible at 4, but not leap because its a century year and is not evenly divisible at 400. So you must also check whether the user entered year is century year or not to decide correctly. (optional : also add 2-3 lines multi-line comment in your program that explains why we need leap years and why Feb days are 29 in leap year. see http://www.mathsisfun.com/leap-years.html).

_______________

5. Get an integer n from user. Print first n prime numbers.

_______________

6. Declare and initialize byte, short, int, float, long, double, boolean type variables using literals, change those values by user input and then print all of 8 variables on input console using format specifiers.

_______________

7. Get 5 digits integer number from user input and print each digits on a separate line.

_______________

8. Get a double vaue from user and print its sin, cos, tan, ceiling, floor, log, etc. using different functions of Math class. See this link for function names: https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html

_______________

9. User java.util.Random class's nextInt(int n) method to generate a random number between 0 to (n-1). To roll a dice 1000 times. and print the average number you get. Print number int value using some function of Math class.

6. Declare and initialize byte, short, int, float, long, double, boolean type variables using literals, change those values by user input and then print all of 8 variables on input console using format specifiers.

_______________

7. Get 5 digits integer number from user input and print each digits on a separate line.

_______________

8. Get a double vaue from user and print its sin, cos, tan, ceiling, floor, log, etc. using different functions of Math class. See this link for function names: https://docs.oracle.com/javase/7/docs/api/java/lang/Math.html

_______________

9. User java.util.Random class's nextInt(int n) method to generate a random number between 0 to (n-1). To roll a dice 1000 times. and print the average number you get. Print number int value using some function of Math class.

## Comments

## Post a Comment