0% found this document useful (0 votes)
18 views18 pages

Java Assignment

Java assigment

Uploaded by

Vishal 77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views18 pages

Java Assignment

Java assigment

Uploaded by

Vishal 77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

02-FIRST JAVA

# [Video Link](https://youtu.be/TAtrPoaJ7gc)

## Write Java programs for the following:

1. Write a program to print whether a number is even or odd, also take

input from the user.

2. Take name as input and print a greeting message for that particular
name.

3. Write a program to input principal, time, and rate (P, T, R) from the
user and find Simple Interest.

4. Take in two numbers and an operator (+, -, *, /) and calculate the


value.

(Use if conditions)

5. Take 2 numbers as input and print the largest number.

6. Input currency in rupees and output in USD.

7. To calculate Fibonacci Series up to n numbers.

8. To find out whether the given String is Palindrome or not.

9. To find Armstrong Number between two given number.

03-CONDITIONAL LOOPS

# [Video Link](https://youtu.be/ldYLYRNaucM)
## Write Java programs for the following:

### Basic Java Programs

1. Area Of Circle

2. Area Of Triangle

3. Area Of Rectangle

4. Area Of Isosceles Triangle

5. Area Of Parallelogram

6. Area Of Rhombus

7. Area Of Equilateral Triangle

8. Perimeter Of Circle

9. Perimeter Of Equilateral Triangle

10. Perimeter Of Parallelogram

11. Perimeter Of Rectangle

12. Perimeter Of Square

13. Perimeter Of Rhombus

14. Volume Of Cone

15. Volume Of Prism

16. Volume Of Cylinder

17. Volume Of Sphere


18. Volume Of Pyramid

19. Curved Surface Area Of Cylinder

20. Total Surface Area Of Cube

21. Fibonacci Series In Java Programs

22. [Subtract the Product and Sum of Digits of an Integer]

(https://leetcode.com/problems/subtract-the-product-and-sum-of-
digits-of-an-integer/)

23. Input a number and print all the factors of that number (use loops).

24. Take integer inputs till the user enters 0 and print the sum of all
numbers (HINT: while loop)

25. Take integer inputs till the user enters 0 and print the largest
number from all.

26. Addition Of Two Numbers

### Intermediate Java Programs

1. Factorial Program In Java

2. Calculate Electricity Bill

3. Calculate Average Of N Numbers

4. Calculate Discount Of Product

5. Calculate Distance Between Two Points

6. Calculate Commission Percentage


7. Power In Java

8. Calculate Depreciation of Value

9. Calculate Batting Average

10. Calculate CGPA Java Program

11. Compound Interest Java Program

12. Calculate Average Marks

13. Sum Of N Numbers

14. Armstrong Number In Java

15. Find Ncr & Npr

16. Reverse A String In Java

17. Find if a number is palindrome or not

18. Future Investment Value

19. HCF Of Two Numbers Program

20. LCM Of Two Numbers

21. Java Program Vowel Or Consonant

22. Perfect Number In Java

23. Check Leap Year Or Not

24. Sum Of A Digits Of Number


25. Kunal is allowed to go out with his friends only on the even days of
a given month. Write a program to count the number of days he can go
out in the month of August.

26. Write a program to print the sum of negative numbers, sum of


positive even numbers and the sum of positive odd numbers from a list
of numbers (N) entered by the user. The list terminates when the user
enters a zero.

04-FUNCTIONS

# [Video Link](https://youtu.be/vvanI8NRlSI)

1. [Define two methods to print the maximum and the minimum


number respectively among three numbers entered by the user.]

(https://www.java67.com/2019/05/how-to-find-largest-and-smallest-
of-three-numbers-in-java.html)

2. [Define a program to find out whether a given number is even or


odd.]

(https://www.geeksforgeeks.org/java-program-to-check-if-a-given-
integer-is-odd-or-even/)

3. [A person is eligible to vote if his/her age is greater than or equal to


18. Define a method to find out if he/she is eligible to vote.]

(https://www.efaculty.in/java-programs/voting-age-program-in-java/)
4. [Write a program to print the sum of two numbers entered by user
by defining your own method.](https://code4coding.com/addition-of-
two-numbers-in-java-using-method/)

5. [Define a method that returns the product of two numbers entered


by user.]

(https://code4coding.com/java-program-to-multiply-two-numbers-
using-method/)

6. [Write a program to print the circumference and area of a circle of


radius entered by user by defining your own method.]

(https://beginnersbook.com/2014/01/java-program-to-calculate-area-
and-circumference-of-circle/)

7. [Define a method to find out if a number is prime or not.]

(https://www.geeksforgeeks.org/java-program-to-check-if-a-number-
is-prime-or-not/)

8. [Write a program that will ask the user to enter his/her marks (out of
100). Define a method that will display grades according to the marks
entered as below:]

(https://www.techcrashcourse.com/2017/02/java-program-to-
calculate-grade-of-students.html)

<br/>

<pre>

Marks Grade

91-100 AA
81-90 AB

71-80 BB

61-70 BC

51-60 CD

41-50 DD

<=40 Fail

</pre>

9. [Write a program to print the factorial of a number by defining a


method named 'Factorial'.]

(https://www.javatpoint.com/factorial-program-in-java)

Factorial of any number n is represented by n! and is equal to 1 * 2 * 3


* .... * (n-1) *n. E.g.- <br/>

<pre>

4! = 1 * 2 * 3 * 4 = 24

3! = 3 * 2 * 1 = 6

2! = 2 * 1 = 2

Also,

1! = 1

0! = 1

</pre>
10. [Write a function to find if a number is a palindrome or not. Take
number as parameter.]

(https://www.geeksforgeeks.org/check-if-a-number-is-palindrome/)

11. Convert the programs in [flow of program](01-flow-of-


program.md), [first java](02-first-java.md), [conditionals & loops](03-
conditionals-loops.md) assignments into functions.

12. [Write a function to check if a given triplet is a Pythagorean triplet


or not.]

(https://www.geeksforgeeks.org/find-pythagorean-triplet-in-an-
unsorted-array/)

(A Pythagorean triplet is when the sum of the square of two numbers is


equal to the square of the third number).

13. [Write a function that returns all prime numbers between two given
numbers.]

(https://www.geeksforgeeks.org/program-to-find-prime-numbers-
between-given-interval/)

14. [Write a function that returns the sum of first n natural numbers.]

(https://www.geeksforgeeks.org/program-find-sum-first-n-natural-
numbers/)

05-ARRAY

# [Video Link](https://youtu.be/n60Dn0UsbEk)

## Submit the following on your Leetcode profile itself.


### Easy

1. [Build Array from Permutation]

(https://leetcode.com/problems/build-array-from-permutation/)

2. [Concatenation of Array]

(https://leetcode.com/problems/concatenation-of-array/)

3. [Running Sum of 1d Array]

(https://leetcode.com/problems/running-sum-of-1d-array/)

4. [Richest Customer Wealth]

(https://leetcode.com/problems/richest-customer-wealth/)

5. [Shuffle the Array]

(https://leetcode.com/problems/shuffle-the-array/)

6. [Kids With the Greatest Number of Candies]

(https://leetcode.com/problems/kids-with-the-greatest-number-of-
candies/)

7. [Number of Good Pairs]

(https://leetcode.com/problems/number-of-good-pairs/)

8. [How Many Numbers Are Smaller Than the Current Number]

(https://leetcode.com/problems/how-many-numbers-are-smaller-than-
the-current-number/)
9. [Create Target Array in the Given Order]

(https://leetcode.com/problems/create-target-array-in-the-given-
order/)

10. [Check if the Sentence Is Pangram]

(https://leetcode.com/problems/check-if-the-sentence-is-pangram/)

11. [Count Items Matching a Rule]

(https://leetcode.com/problems/count-items-matching-a-rule/)

12. [Find the Highest Altitude]

(https://leetcode.com/problems/find-the-highest-altitude/)

13. [Flipping an Image]

(https://leetcode.com/problems/flipping-an-image/)

14. [Cells with Odd Values in a Matrix]

(https://leetcode.com/problems/cells-with-odd-values-in-a-matrix/)

15. [Matrix Diagonal Sum]

(https://leetcode.com/problems/matrix-diagonal-sum/)

16. [Find Numbers with Even Number of Digits]

(https://leetcode.com/problems/find-numbers-with-even-number-of-
digits/)

17. [Transpose Matrix]

(https://leetcode.com/problems/transpose-matrix/)
18. [Add to Array-Form of Integer]

(https://leetcode.com/problems/add-to-array-form-of-integer/)

19. [Maximum Population Year]

(https://leetcode.com/problems/maximum-population-year/)

20. [Determine Whether Matrix Can Be Obtained By Rotation]

(https://leetcode.com/problems/determine-whether-matrix-can-be-
obtained-by-rotation/)

21. [Two Sum]

(https://leetcode.com/problems/two-sum/)

22. [Find N Unique Integers Sum up to Zero]

(https://leetcode.com/problems/find-n-unique-integers-sum-up-to-
zero/)

23. [Lucky Number In a Matrix]

(https://leetcode.com/problems/lucky-numbers-in-a-matrix/)

24. [Maximum Subarray]

(https://leetcode.com/problems/maximum-subarray/)

25. [Reshape the Matrix]

(https://leetcode.com/problems/reshape-the-matrix/)

26. [Plus One]

(https://leetcode.com/problems/plus-one/)
27. [Remove Duplicates from Sorted Array]

(https://leetcode.com/problems/remove-duplicates-from-sorted-
array/)

28. [Minimum Cost to Move Chips to The Same Position]

(https://leetcode.com/problems/minimum-cost-to-move-
chips-to-the-same-position/)

### Medium

1. [Spiral Matrix]

(https://leetcode.com/problems/spiral-matrix/)

2. [Spiral Matrix II]

(https://leetcode.com/problems/spiral-matrix-ii/)

3. [Spiral Matrix III]

(https://leetcode.com/problems/spiral-matrix-iii/)

4. [Set Matrix Zeroes]

(https://leetcode.com/problems/set-matrix-zeroes/)

5. [Product of Array Except Self]

(https://leetcode.com/problems/product-of-array-except-self/)

6. [Find First and Last Position of Element in Sorted Array]


(https://leetcode.com/problems/find-first-and-last-position-of-
element-in-sorted-array/)

7. [Jump Game]

(https://leetcode.com/problems/jump-game/)

8. [Rotate Array]

(https://leetcode.com/problems/rotate-array/)

9. [Sort Colors]

(https://leetcode.com/problems/sort-colors/)

10. [House Robber]

(https://leetcode.com/problems/house-robber/)

### Hard

1. [Max Value of Equation]

(https://leetcode.com/problems/max-value-of-equation/)

2. [First Missing Positive]

(https://leetcode.com/problems/first-missing-positive/)

3. [Good Array]

(https://leetcode.com/problems/check-if-it-is-a-good-array/)
14-OBJECT ORIENTED PROGRAMMING

# Important Topics-

[Kunal's notes]

(https://github.com/kunal-kushwaha/DSA-Bootcamp-
Java/tree/main/lectures/17-oop/notes) –

[Object Oriented Paradigms]

(https://www.geeksforgeeks.org/object-oriented-programming-oops-
concept-in-java/) `GFG`-

[Constructors in Java]

(https://www.geeksforgeeks.org/constructors-in-java/) `GFG-
[Constructor chaining in Java]

(https://www.geeksforgeeks.org/constructor-chaining-java-examples/)
`GFG`-

[Inheritance in Java]

(https://www.geeksforgeeks.org/inheritance-in-java/) `GFG`-
[Overriding in Java]

(https://www.geeksforgeeks.org/overriding-in-java/) `GFG -
[Abstraction in Java]

(https://www.geeksforgeeks.org/abstraction-in-java-2/) `GFG`-

[Access modifiers in Java]

(https://www.geeksforgeeks.org/access-modifiers-java/) `GFG`-
[Wrapper Classes in Java]
(https://www.geeksforgeeks.org/wrapper-classes-java/) `GFG`-

[Need of wrapper classes in Java]

(https://www.geeksforgeeks.org/need-of-wrapper-classes-in-java/)
`GFG`

- [this keyowrd in Java]

(https://www.javatpoint.com/this-keyword) `Javatpoint`

- [Important keyowrds in Java inheritance -


extends,implements,super,instanceof]

(https://www.tutorialspoint.com/java/java_inheritance.htm)
`Tutorialspoint`

- [Instance initializer block]

(https://www.javatpoint.com/instance-initializer-block) `Javatpoint`

- [Dynamic Method Dispatch or Runtime Polymorphism in Java]

(https://www.geeksforgeeks.org/dynamic-method-dispatch-runtime-
polymorphism-java/) `GFG`

- [Cohesion in Java

](https://www.geeksforgeeks.org/cohesion-in-java/) `GFG`

- [Coupling in Java]

(https://www.geeksforgeeks.org/coupling-in-java/) `GFG`

# Interview Questions
- [Can we declare main() method as private or protected or with no
access modifier in java?]

(https://www.tutorialspoint.com/can-we-declare-main-method-as-
private-or-protected-or-with-no-access-modifier-in-java)
`Tutorialspoint`

- [Difference between Method Overloading and Method Overriding in


Java?]

(https://www.geeksforgeeks.org/difference-between-method-
overloading-and-method-overriding-in-java/) `GFG`

- [Can we declare interface members as private or protected in java8?]

(https://www.tutorialspoint.com/can-we-declare-interface-members-
as-private-or-protected-in-java8) `Tutorialspoint`

- [Can we override a private or static method in Java?]

(https://www.tutorialspoint.com/can-we-override-a-private-or-static-
method-in-java) `Tutorialspoint`

- [What is diamond problem in Java?]

(https://www.javatpoint.com/what-is-diamond-problem-in-java)
`Javatpoint`

- [Can we pass this keyword as argument in a method call?]

(https://www.javatpoint.com/this-
keyword#:~:text=this%3A%20to%20pass%20as%20an%20argument%2
0in%20the%20method) `Javatpoint`

- [Java constructor returns a value, but what?]


(https://www.javatpoint.com/java-constructor-returns-a-value-but-
what) `Javatpoint`

- [What is covariant return type?]

(https://www.javatpoint.com/covariant-return-type) `Javatpoint`

- [Private classes and singleton classes in Java]

(https://www.geeksforgeeks.org/private-constructors-and-singleton-
classes-in-java/) `GFG`

- [How to prevent Singleton Pattern from Reflection, Serialization and


Cloning?]

(https://www.geeksforgeeks.org/prevent-singleton-pattern-reflection-
serialization-cloning/) `GFG`

- [Double-Check Locking For Singleton Class]

(https://www.geeksforgeeks.org/java-program-to-demonstrate-the-
double-check-locking-for-singleton-class/) `GFG`

# Practice Problems

- [Inheritance I]

(https://www.hackerrank.com/challenges/java-inheritance-
1/problem?isFullScreen=true) `HackerRank`-

[Inheritance II]

(https://www.hackerrank.com/challenges/java-inheritance-
2/problem?isFullScreen=true) `HackerRank`-
[Java Abstract class]

(https://www.hackerrank.com/challenges/java-abstract-
class/problem?isFullScreen=true) `HackerRank`

- [Interface]

(https://www.hackerrank.com/challenges/java-
interface/problem?isFullScreen=true) `HackerRank`-

[Method Overriding I]

(https://www.hackerrank.com/challenges/java-method-
overriding/problem?isFullScreen=true) `HackerRank`-

[Method Overriding II (Use super keyword)]

(https://www.hackerrank.com/challenges/java-method-overriding-2-
super-keyword/problem?isFullScreen=true) `HackerRank`-

[Java instanceof keyword]

(https://www.hackerrank.com/challenges/java-instanceof-
keyword/problem?isFullScreen=true) `HackerRank`-

[Java Iterator]

(https://www.hackerrank.com/challenges/java-
iterator/problem?isFullScreen=true) `HackerRank`

You might also like