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

JAVA Coding IMP

The document discusses 11 Java programming concepts and code snippets: 1) Reversing a string, 2) Generating Fibonacci series, 3) Finding largest and smallest number in an array, 4) Searching an array, 5) Sorting an array, 6) Removing unwanted characters from a string, 7) Reversing words in a string, 8) Finding a substring in a string, 9) Finding duplicates in an array, 10) Static keyword questions, and 11) Finding duplicate characters in a string. Code examples are provided for each concept using techniques like loops, arrays, strings, and maps.

Uploaded by

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

JAVA Coding IMP

The document discusses 11 Java programming concepts and code snippets: 1) Reversing a string, 2) Generating Fibonacci series, 3) Finding largest and smallest number in an array, 4) Searching an array, 5) Sorting an array, 6) Removing unwanted characters from a string, 7) Reversing words in a string, 8) Finding a substring in a string, 9) Finding duplicates in an array, 10) Static keyword questions, and 11) Finding duplicate characters in a string. Code examples are provided for each concept using techniques like loops, arrays, strings, and maps.

Uploaded by

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

1) Reverse a String = https://bit.

ly/3Qa34bn

String str="Sridhar"
String b="";
char ch;
for(int i=0;i<str.length();i++)
{
ch=str.CharAt(i)
b=ch+b;
}
Sysout("the reverse string is:" +b);
}
}

2) Generate Fibonacci series = https://bit.ly/3Z7k5Y7

int a=0;
int b=1;
for(int i=0;i<=10;i++) {
int c=a+b;
a=b;
b=c;
System.out.println(a);

3) Find largest and smallest in an array = https://bit.ly/3Z1TnA3

int[]ar= {2,34,21,32,67,45,3334,8};
int max=ar[0];
int min=ar[0];
for(int i=0;i<ar.length;i++) {
if(ar[i]>max) {
max=ar[i];
}
if(ar[i]>min) {
min=ar[i];
}
}
System.out.println("max is: "+max);
System.out.println("min is: "+min);

4) Search element in an array = https://bit.ly/3G8LrnS

5) Sort elements in an array = https://bit.ly/3i8b6VS

6) How to remove unwanted characters from string = https://bit.ly/3Icqs6m

7) How to reverse each word = https://bit.ly/3WD4y0w


8) Find given substring is presence = https://bit.ly/3G6w5jT

9) How to find duplicates = https://bit.ly/3i5usuD

int[] arr = {1, 2, 5, 5, 6, 6, 7, 2};


for (int i = 0; i < arr.length; i++)
{
for (int j = i; j < arr.length; j++)
{
if ((arr[i] == arr[j]) && (i != j))
{
System.out.println("Duplicate Elements : " + arr[j]);
}
}
}

10) Static keyword questions = https://bit.ly/3Z5kVEz

11) find the DuplicateCharacters in a given string

String str="Sridharerra";

Map<Character,Interger> charCountMap=new HashMap<>();


for(char ch:str.toCharArray())
{
if(charCountMap.Contatinskey(ch));
{
charCountMap.put(ch,charCountMap.get(ch)+1);
}
else
{
charCountMap.put(ch,1);
}
}
Sysout(charCountMap);

https://www.youtube.com/playlist?
list=PLqdHI1COI61OA6skF0cJ2H1TF7CbTw9oz=================

You might also like