0% found this document useful (0 votes)
10 views

Java Basics Task 1

Uploaded by

srinivasan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Java Basics Task 1

Uploaded by

srinivasan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Basic Java Concepts Task 1

Note:
1. Try to solve the problems just get the logic from google and try to implement the
logic on your own.
2. Run the logic in Eclipse and Write all the solu on in a word document ques on and
answer below. Below is the sample:
1. Check Posi ve or Nega ve:
public sta c void main(String[] args) {
scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
double number = scanner.nextDouble();
if (number > 0) {
System.out.println("The number is posi ve.");
}
else if (number < 0) {
System.out.println("The number is nega ve.");
}
else {
System.out.println("The number is zero.");
}
scanner.close();
}

30 Simple Problems:
1. Check Posi ve or Nega ve
- Write a program to check whether a number is posi ve or nega ve using `if-else`.

2. Odd or Even Number


- Determine if a number is odd or even using the modulus operator and `if-else`.

3. Vowel or Consonant
- Check if a given character is a vowel or consonant using `if-else`.

4. Simple Calculator
- Implement a simple calculator using a `switch` statement to perform addi on, subtrac on,
mul plica on, or division.

5. Grade Assignment
- Assign a grade (A, B, C, D, F) based on a score input by the user using `if-else`.

6. Print Day of the Week


- Use a `switch` statement to print the name of the day based on a number input (1 for Monday, 2
for Tuesday, etc.).

7. Check Eligibility to Vote


- Write a program that checks if a person is eligible to vote based on their age using `if-else`.

8. Find the Largest of Two Numbers


- Use `if-else` to find the largest of two numbers provided by the user.

9. Leap Year Check


- Determine if a year is a leap year using `if-else`.
10. Print Numbers from 1 to 10
- Use a `for` loop to print numbers from 1 to 10.

11. Sum of First N Natural Numbers


- Calculate the sum of the first N natural numbers using a `for` loop.

12. Reverse a String


- Write a program to reverse a string using a `for` loop.

13. Factorial Calcula on


- Calculate the factorial of a number using a `for` loop.

14. Mul plica on Table


- Print the mul plica on table of a number using a `for` loop.

15. Count Digits in a Number


- Use a `while` loop to count the number of digits in a given integer.

16. Sum of Digits


- Write a program to find the sum of the digits of a number using a `while` loop.

17. Print First 10 Odd Numbers


- Use a `for` loop to print the first 10 odd numbers.

18. Print Numbers in Reverse Order


- Print numbers from 10 to 1 using a `for` loop.

19. Fibonacci Series


- Print the first 10 numbers in the Fibonacci series using a `for` loop.

20. Check if a Number is Prime


- Write a program to check if a number is prime using a `for` loop.

21. Simple Interest Calcula on


- Calculate simple interest using a method with principal, rate, and me as inputs.

22. Temperature Conversion


- Write a method to convert temperature from Celsius to Fahrenheit.

23. Power of a Number


- Write a program to calculate the power of a number using a `for` loop.

24. Check Palindrome


- Write a program to check if a string is a palindrome using a `for` loop.

25. Calculate Area of Circle


- Write a method that calculates and returns the area of a circle given the radius.

26. Find Largest of Three Numbers


- Use `if-else` to find the largest of three numbers.

27. Check Armstrong Number


- Write a program to check if a number is an Armstrong number using a `while` loop.

28. Sum of Even Numbers


- Use a `for` loop to find the sum of all even numbers up to a given number.

29. Check Divisibility by 5


- Write a program that checks if a number is divisible by 5 using `if-else`.

30. Simple Login System


- Implement a simple login system using `if-else` to validate the username and password.

30 Medium-Level Problems

1. Find the GCD of Two Numbers


- Write a program to find the greatest common divisor (GCD) of two numbers using a `while` loop.

2. Number Guessing Game


- Implement a number guessing game using a `while` loop where the user has to guess a randomly
generated number.

3. Simple Menu-Driven Program


- Create a menu-driven program using a `switch` statement that allows the user to perform different
opera ons like addi on, subtrac on, etc.

4. Print Prime Numbers up to N


- Write a program to print all prime numbers up to N using nested `for` loops.

5. Find LCM of Two Numbers


- Write a program to find the least common mul ple (LCM) of two numbers using a `for` loop.

6. Palindrome Number Check


- Write a program to check if a number is a palindrome using a `while` loop.

7. Matrix Addi on
- Perform matrix addi on using nested `for` loops.

8. Matrix Mul plica on


- Perform matrix mul plica on using nested `for` loops.

9. Binary to Decimal Conversion


- Convert a binary number to a decimal number using a method.

10. Decimal to Binary Conversion


- Convert a decimal number to a binary number using a method.

11. Check for Perfect Number


- Write a program to check if a number is a perfect number using a `for` loop.

12. Reverse a Number


- Write a program to reverse the digits of an integer using a `while` loop.

13. Print Armstrong Numbers up to N


- Write a program to print all Armstrong numbers up to N using a `for` loop.

14. Bubble Sort


- Implement the bubble sort algorithm using nested `for` loops.

15. Check if a Number is Palindrome Using Methods


- Write a method to check if a given number is a palindrome.

16. Convert Case of a Character


- Write a method to convert a lowercase character to uppercase and vice versa.

17. Sum of Array Elements


- Write a method to calculate the sum of all elements in an array.

18. Find Largest Element in Array


- Write a method to find the largest element in an array.

19. Sort Array in Ascending Order


- Implement a program to sort an array in ascending order using a sor ng algorithm and a `for` loop.

20. Calculate Power Using Recursion


- Write a recursive method to calculate the power of a number.

21. Check for Anagram Strings


- Write a method to check if two strings are anagrams of each other.

22. Find Factorial Using Recursion


- Write a recursive method to find the factorial of a number.

23. Check if a Year is a Leap Year Using Methods


- Write a method that checks if a year is a leap year.

24. Fibonacci Series Using Recursion


- Implement a method to generate Fibonacci series using recursion.

25. Count Vowels in a String


- Write a method that counts the number of vowels in a given string.

26. Count Words in a Sentence


- Write a method that counts the number of words in a sentence.

27. Simple Interest Calculator Using Methods


- Write a method to calculate simple interest and return the result.

28. Find Second Largest Element in an Array


- Write a program to find the second largest element in an array using a `for` loop.

29. Remove Duplicates from Array


- Write a program to remove duplicates from an array using a `for` loop.

30. Implement Linear Search


- Implement a linear search algorithm to find an element in an array using a method.

15 Simple Problems (Strings and Arrays)

1. Count Characters in a String


- Write a program to count the number of characters in a string.

2. Check if a String is Empty


- Write a program to check if a given string is empty or not.
3. Convert String to Uppercase
- Write a program that converts a string to uppercase.

4. Convert String to Lowercase


- Write a program that converts a string to lowercase.

5. Concatenate Two Strings


- Write a program to concatenate two strings.

6. Find the Length of a String


- Write a program to find and print the length of a string.

7. Check if a String Contains a Substring


- Write a program to check if a given substring is present in a string.

8. Replace Characters in a String


- Write a program to replace all occurrences of a specific character in a string with another character.

9. Check if Two Strings are Equal


- Write a program to check if two strings are equal.

10. Reverse an Array


- Write a program to reverse the elements of an array.

11. Find the Sum of Array Elements


- Write a program to calculate the sum of all elements in an array.

12. Find the Minimum Element in an Array


- Write a program to find the smallest element in an array.

13. Find the Maximum Element in an Array


- Write a program to find the largest element in an array.

14. Check if an Array Contains a Specific Value


- Write a program to check if a specific value is present in an array.

15. Sort an Array in Ascending Order


- Write a program to sort the elements of an array in ascending order.

15 Medium-Level Problems (Strings and Arrays)

1. Count Vowels and Consonants in a String


- Write a program to count the number of vowels and consonants in a string.

2. Check if a String is a Palindrome


- Write a program to check if a given string is a palindrome.

3. Remove All White Spaces from a String


- Write a program to remove all white spaces from a string.

4. Count Words in a String


- Write a program to count the number of words in a string.

5. Find the First Non-Repeated Character in a String


- Write a program to find the first non-repeated character in a string.

6. Check if Two Strings are Anagrams


- Write a program to check if two given strings are anagrams of each other.

7. Reverse Each Word in a Sentence


- Write a program to reverse each word in a sentence.

8. Find All Substrings of a String


- Write a program to find and print all substrings of a given string.

9. Remove Duplicates from a String


- Write a program to remove all duplicate characters from a string.

10. Merge Two Arrays


- Write a program to merge two arrays into one.

11. Find the Second Largest Element in an Array


- Write a program to find the second largest element in an array.

12. Remove Duplicates from an Array


- Write a program to remove duplicate elements from an array.

13. Find the Intersec on of Two Arrays


- Write a program to find the common elements between two arrays.

14. Rotate an Array


- Write a program to rotate the elements of an array to the right by a given number of posi ons.

15. Find the Pair of Elements with a Given Sum


- Write a program to find all pairs of elements in an array whose sum is equal to a specified number.

You might also like