I want to create a a program in which i enter a word and the program counts the number of alphabets used in the word and display as output !!
I know its simple but i am just a beginner and my teacher wants to submit this as assignment


this is the question
2. A man wanted to enter a club but did not know the password that was required. He waited by the door and listend, a club member knocked on the door, the door man said "twelve" member replied "6" and was let in. Second member came to the door, doorman said "six" the member replied "3" and was let in. now the man throught that he had heard enough and walked up to the door, doorman said "eight" the man replied "4" but he was not let in. What should he say? so that he gets in.

Edited 7 Years Ago by ayaz.ali: question added

i have no clue how to do it ??
i only started working a week ago i just know how to introduce integer and if and else and print hello world :p

the program counts the number of alphabets used in the word and display as output !!

I'm guessing that by "the number of alphabets" you mean the number of letters your word has. If I'm guessing wright then use length() method of the String class.
Hava a look at the String class and at the trails.


2. A man wanted to enter a club but did not know the password that was required. He waited by the door and listend, a club member knocked on the door, the door man said "twelve" member replied "6" and was let in. Second member came to the door, doorman said "six" the member replied "3" and was let in. now the man throught that he had heard enough and walked up to the door, doorman said "eight" the man replied "4" but he was not let in. What should he say? so that he gets in.

What do you mean by that? Is it some kind of joke I didn't get?

What do you mean by that? Is it some kind of joke I didn't get?

That is the example for his problem.

this is the answer about the count:

int counter (string s){
count=0;
for (int i=1;int i<s.length();i++)
count ++;
return count;
}

this is the answer about the count:

int counter (string s){
count=0;
for (int i=1;int i<s.length();i++)
count ++;
return count;
}

Um, no... just no.

this is the answer about the count:

int counter (string s){
count=0;
for (int i=1;int i<s.length();i++)
count ++;
return count;
}

No offense but this was worthless.How about using the s.length().
It already is a function that returns the number of character. And your counter has bugs.

Edited 7 Years Ago by firstPerson: n/a

there is another way to solve this one i got it and told my teacher also made the program from it at last minute

12+6=18 which is divisble by 9 %=0
6+3=9 same %=0
so the answer will be 8+1=9 %=0

import java.util.Scanner;

class Guard
{	
	public static void main(String args[])
	{
	 int a;
	 int b;
	 int c;
	 int rm;
	
	Scanner input=new Scanner (System.in);
		System.out.print("Enter the digit that the guard has given you:");
	a=input.nextInt();
		System.out.print("Please enter your password:");
	b=input.nextInt();
	
	
	c = a + b;
	rm = c%9;
	

	if (rm==0 && b<9)
	System.out.println("Access granted ");
	
	else
	System.out.println("Wrong Password! Access denied");

	}
}

Edited 7 Years Ago by ~s.o.s~: Added code tags, please learn to use them.

write a problem that determines the GCD of pairs of positive integers. the program shall repeatedly request for integer pairs and determine the GCD until one of the inputs received is less than 1.

I want to create a a program in which i enter a word and the program counts the number of alphabets used in the word and display as output !!
I know its simple but i am just a beginner and my teacher wants to submit this as assignment


this is the question
2. A man wanted to enter a club but did not know the password that was required. He waited by the door and listend, a club member knocked on the door, the door man said "twelve" member replied "6" and was let in. Second member came to the door, doorman said "six" the member replied "3" and was let in. now the man throught that he had heard enough and walked up to the door, doorman said "eight" the man replied "4" but he was not let in. What should he say? so that he gets in.

ans is [5] as word 'eight' contains 5 letters in it (as you can see in above eg. given............as in 'twelve' it contain 6 letters as in 'six' it contains 3 letter s

This article has been dead for over six months. Start a new discussion instead.