Task 01 - Java Basics

Post Updated on: Sep. 18. 2021

Task 01 Objects:
  1. Writing, compiling and running basic program in Java
  2. Using primitive data types and their literals
  3. Getting input from user of different primitive types
  4. Using if/else, loops and defining methods in Java
Below given tasks are very basic in nature. They are to make you comfortable with how to write code in Java using variables, if/else and loops, printing output at console using different methods.

1.1 
Initialize a variable n with some +ve integer value. Then create implement logic to print first n prime numbers on console. 

1.2
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 7 variables on console. (in lab video, you have already seen, how to get input from user using Scanner class)

1.3 
Get a 4 digit integer number from user input and print each digits on a separate line.

1.4 
Get an integer from user 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, when valid number is given break the loop). Your program should print, is the year 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)

1.5 
Get an integer for table number, start value and end value. all integer. your program should print a table... from start to end value. For example, here is sample run:
Enter table #: 3
Enter start #: 7
Enter end #: 9
7 x 3 = 21
8 x 3 = 24
9 x 3 = 27


1.6 
Write a java program that shall get two numbers from user of double type. It shall print the remainder when first is divided by second. it shall also print ... whether first is divisble by second or not.
Example output:
Enter first no. 7
Enter second num: 2
The remainder is 1
7 is not divisible by 2

1.7
Get applicant age, marks in math, english and science from user. Write a program to find the eligibility of admission for a professional course based on the following criteria: To be eligible for admission, following conditions must be met:
Age must be greater than 15
Marks in math should be greater or equals to 65
Marks in english should be greaer or equals to 55
Marks in science must be greater than 50
Total marks of all three subjects must be >=180
Your programs shall print "Eligible for admission" or "Not eligible for admission", depending on data given by user.

1.8
Let's say, a number is 'special' if its divisble by 2, 3 but not by 7. Can you count and print how many and which numbers are special starting from 1 to a number given by user. Sample:
Enter end number: 18
Special Number Count: 3
Following are special: 6, 12, 18
(Note: there is no objective of finding special numbers... its only to learn building logic)

1.9
Get the basic salary of employee from user input, write a program that shall calculate gross salary using given details:
for basic aalary below 10000, house rent allowance is 50% and medical allowance is 10%
for basic salary between 10000 and 20000, HRA = 60% and MA = 15%
when Basic Salary is above 20000, HRA = 70% and MA = 20%

1.10
Calculate total salary based on commission and bonus. Get sale amount from user input.
Assume, 2% commission when sales is less than or equals to 100,000. 1.5% commission if sales above 100,000 and below 300,000 with additional bonus of 2000. 1% if sales above 300,000 with 3000 bonus. Calculate total payables to employee, assume fix salary is 25,000 (which is minimum salary of employee and always paid, irrespective of sales)?

Comments