ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
Write program to print Hello World and print each character
address in that string and print how many times each
character is in that string?
    Ex: H: 0 & 1
        e:1 & 1
        l :2,3,8 & 3
        o:4,6 & 2
        w:5 & 1
        r: 7 & 1
        d 9 & 1
 Question Submitted By :: Seenu
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Write program to print Hello World and print each character address in that string and print how many times each character is in that string? Ex: H: 0 & 1 e:1 & 1 l :2,3,8 & 3 o:4,6 & 2 w:5 & 1 r: 7 & 1 d 9 & 1
Answer
# 1
class Wordcount
{
	public static void main(String[] args)
	{

		String s="hello world";

		for(int i=0;i<s.length();i++)
		{
			String s1=""+i;

			int count=1;
			if(s.charAt(i)!=' ')
			{

				for(int j=i+1;j<s.length();j++)
				{
					if(s.charAt(i)==s.charAt(j))
					 {
					  count++;
					  s1=s1+"&"+j;
					 }
				}
				int before=0;
				for(int x=i-1;x>0;x--)
				{
					if(s.charAt(i)==s.charAt(x))
					before=1;
				}
				if(before==0)
				  System.out.println("the occurence of letter "+s.charAt(i)+" no of times= "+count+"--- positions="+s1);
		    }

		}
	
	}
}
 
Is This Answer Correct ?    0 Yes 1 No
Kishore Nerella
 
  Re: Write program to print Hello World and print each character address in that string and print how many times each character is in that string? Ex: H: 0 & 1 e:1 & 1 l :2,3,8 & 3 o:4,6 & 2 w:5 & 1 r: 7 & 1 d 9 & 1
Answer
# 2
Little change in the code

add this for loop
for (int x = i - 1; x >= 0; x--) 

instead of
for (int x = i - 1; x > 0; x--)
 
Is This Answer Correct ?    0 Yes 0 No
Noor
 
 
 
  Re: Write program to print Hello World and print each character address in that string and print how many times each character is in that string? Ex: H: 0 & 1 e:1 & 1 l :2,3,8 & 3 o:4,6 & 2 w:5 & 1 r: 7 & 1 d 9 & 1
Answer
# 3
public class WordCount {
	public static void main(String args[])
	{
		String s = "HelloWorld";

		for(int i=0; i<s.length(); i++)  //Track 
each character
		{
			int flag = 0, count = 0;
			for(int j=i-1; j>=0; j--)
	//This loop is for: If character repeats or Space 
then skip to next character
			{
				if(s.charAt(j) == s.charAt
(i) || s.charAt(i) == ' ')
				{
					flag = 1;
					break;
				}
			}
			if(flag == 1)
				continue;
			
			System.out.print(s.charAt(i) 
+ ": ");    //Starts to check position and counter for 
repeated characters
			for(int k=i; k<s.length(); k++)
			{
				if(s.charAt(i) == s.charAt
(k))
				{
					count++;
					if(k == 
i)                  //Just for nice output
					
	System.out.print(k);
					else
					
	System.out.print("," + k);
				}
			}
			System.out.println(" & " + 
count);     //end output line with count
		}
	}
}
 
Is This Answer Correct ?    1 Yes 0 No
Nagvthu@gmail.com
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
When finalize method is called?  3
What is update method and when it is called?  1
What is difference between Iterator and for loop  4
What are integer overflows and underflows and how to handle them? Wipro2
what is Thread?  6
Different types of Layouts?  5
Difference between this(), super()?  8
I/O blocking means?  1
Name the method that is used to set a TextComponent to the read-only state?  1
Without creating a new object, How you can retrieve a String or other object?  1
explain System.out.println IBM41
How will you create the class for the following scenario? Employees under one employee? Bally-Technologies2
By what default value is an object reference declared as an instance variable? Wipro1
What is the purpose of premetive data types in java? Merrill-Lynch2
What is the superclass of exception?  2
What is compile time polymorphism? Elementus-Technologies6
What is the need to implement Serializable interface (with no methods) for objects which are to be serialized ? We can write our own functionality which writes objects to streams then why we need to implement and tell JVM that which objects can be serialized. iFlex4
Can applet in different page/s communicate with each other?  1
Can we add two byte variables and assign the result to a byte variable ? b=b1+b2 where b,b1,b2 are byte types TCS3
When does the compiler supply a default constructor for a class? TCS8
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com