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

Java Qns

Uploaded by

Subbu Meeseva
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)
19 views

Java Qns

Uploaded by

Subbu Meeseva
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/ 3

V.V.V.

Imp programs for interview


---------------------------------------
1.Reverse the given string without using third/temparary variable?
2.Reverse the given string using third variable?
3.Reverse the string without using length method or length variable?
-----------------------------
with respect to characters
-----------------------------
4.Find the no.of occurance for each character in the given string?
======
Steps:
==============
1.create set coll(HashSet) and add all the char og given string into set
2.compare each char of set with all char of given string
3.if it is matching ,increament the count
4.print both char and count
===============

5.Print the only duplicate characters in the given string?


6.Print only uniq characters in the given string?
//
7.Remove the duplicate characters in the given string?
------------------
with respect string
-------------------
8.Find the no.of occurance for each word in the given string?
9.Print the only duplicate words in the given string?
10.Print only uniq words in the given string?
11.Remove the duplicate wordss in the given string?

1.Code logic
--------
String s="India";
{
for(int i=s.length()-1;i>=0;i--)
{
System.out.print(s.charAt(i));
}
----------
package Java.Util;

public class ReverseOfString


{
public static void main(String [] args)
{
String s="India";
{
for(int i=s.length()-1;i>=0;i--)
{
System.out.print(s.charAt(i));
}
}
}
}
--------------------
2.code
----------------
package Java.Util;
public class StringThirdVariable
{
public static void main(String[] args)
{
String s="INDIA";
String rev="";
{
for(int i=s.length()-1;i>=0;i--)//5-1=4>=0true Input:I N D I A
//1.0 1 2 3 4-->Index numberSS
{
rev=rev+s.charAt(i);//""+A=A 2.A+I=AI-->AI+D=AID--->AID+N=AIDN---
>AIDN+I=AIDNI
}
System.out.print(rev);//Output: AIDNI
}
}
}
--------------------------------------
3.Code
-------------------------
package Java.Util;

public class StringWithoutLengthMethodVar


{
public static void main(String[] args)
{
String s="INDIA";
{
Char ch[]=s.toCharArray();
int count=0;
for(char a:ch)
{
count++;
}
System.out.println("count="+count);
for(int i=count-1;i>=0;i--)
{
System.out.print(ch[i]);
}
}
}
}
------------------------------------------------------
Assignment
-------------------------------------------------------
1.String s="Welcome to tyss company"?
output:company to tyss Welcome

2.String s="abc12@45xyz%";
output: abcxyz
1245
@%

3.String s="welcome to tyss";


output:"tyss to welcome"-->rev=rev+str[i]+" ";

4.String s="india";
output:i
in
ind
indi
india

5.string s="ab12@c4%5";
output:1 +2 +4 +5=12

You might also like