Here I am presenting 30+ Basic Java Programs.
https://www.programmingempire.com/understanding-map-collection-in-java/
- Create a program that accepts exactly two command line arguments. Otherwise, it should print an error message and exit. When the user enters (1) programmingempire and Delhi, the output should be Programmingempire Team Delhi (2) If the inputs are princites and Ajmer, the output should be Princites Team Ajmer.
- Similarly, in another program accept exactly one command line parameter and display a welcome message. For example, (1) if the input is Cherry, the output is Welcome Cherry. (2) If the input is Charlie, the output should be Welcome Charlie.
- Write another program that accepts exactly two integers as the command line arguments and shows their sum.
- Similarly, check whether a user has entered any command line argument or not. When no argument is in input display No Data. Otherwise, display all arguments.
- Write a program to accept a number as input and display whether it is positive, negative, or zero.
- Find whether the two numbers entered by the user have the same unit’s digit.
- Write a program to find whether an input number is odd or even.
- Take two characters as input and arrange them in alphabetical order.
- Initialize a character variable and display the output as ‘Alphabet’, ‘Digit’, or ‘Special Character’.
- Write a program to display the interest percentage on Fixed Deposit by taking the age and gender (‘Male’ or ‘Female’) as input. In order to calculate the interest percentage, follow these rules. When the gender is Female (i) if the age is between 1 and 48, the interest is 8.6% (ii) For age between 49 and 100, interest is 9.6%. Otherwise (gender is ‘Male’), (i) age: 1-48, interest is 7.4% (ii) age: 49-100, interest is 8.7%.
- Write a program that takes a character and a string as input and displays that in uppercase, if the input is in lowercase. Otherwise, display the input in lowercase.
- Accept as input a character as the color code and display the name of the corresponding color. For instance, if the color code is ‘R’, the color name is ‘Red’. In order to perform it, use a switch-case statement. When the input is not valid, display ‘Invalid Code’.
- Write a program to accept a number between 1 and 12 and display the corresponding month name.
- Display the integers from 1 to 10 separated by a tab.
- Write a program to accept a range and display the even numbers in that range. For instance, the user enters 10 and 20. So, the output should be 10 12 14 16 18 20.
- Find whether a number entered as input is prime or not.
- Also, display prime numbers in a specific range.
- Find and display the sum of digits of a number.
- Also, find the reverse of a number and display it.
- Further, determine if the given number is a palindrome or not.
- Display Floyd’s Triangle using ‘*’.
- Initialize an integer array and display the sum and average of its elements.
- Find maximum and minimum in the array.
- Write a program to search for a value in an integer array. When the value is not present display -1. Otherwise, display its index.
- Display the corresponding character values for the ASCII values present in an array.
- Find the largest two elements and the smallest two elements in an array.
- Write a program to sort an array.
- Remove duplicates from an array.
- Find the sum of elements of an array. However, the following condition applies. Take two numbers as input. When the input numbers appear in the same order in the array ignore all elements including those two numbers while calculating the sum. For instance, input numbers are 12 and 8. (i) When array is {1, 9, 12, 7, 3, 6, 8, 2, 9}, sum= 21 (1+9+2+9) (ii) array: {1, 8, 1, 6, 12, 5}, sum= 33 (1+8+1+6+12+5) (ii) When array is {2, 7, 12, 4, 8, 5}, sum=14 (2+7+5).
- Write a program to remove all occurrences of a given number in an array and move other elements left. Also, place 0 for removed elements. For instance, array={3,2,8,2,2,19,2,4}, input number=2. Hence the output array={3,8,19,4,0,0,0,0}.
- Shift all even elements in an array towards the left. Whereas the odd elements should be on the right side. For instance, input array={3,1,8,12, 9,6,5,8,1,17}. So, the output array={8,12,6,8,3,1,9,5,1,17}.
- Write a program that accepts two integers as input. Also, initialize an array of integers. When the array contains only the occurrences of input integers, the output should be True. Otherwise the output should be False.
- Initialise two integer arrays of three elements each. Further, create a third array of two elements by taking their middle element.
- Create a 2D array by taking elements using command line arguments. Find the reverse of the array.
- Also, find the largest number from a 3 X 3 integer array.