Sythe.Org Forums     Register     FAQ     Members List     Calendar     Mark Forums Read    
 
Sythe.Org Forums  
   Runescape Gold

Sythe.org — A Virtual Goods Trading Hub

Make real cash! buying and selling in-game items.

We have a no-scam policy.

You can make thousands playing your favourite games here at Sythe.org.

Just sign up an account and follow the rules!


Take me to

Runescape Markets

Other Game Markets

Support Center

Register an Account

Close
Help
Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 04-23-2011, 10:12 PM
Grand Master
 
Join Date: Nov 2005
Location: Perth Amboy, NJ...Sorry no lame joke
Posts: 2,455
Default Help



I'm trying to do the second problem there. What would I have to do to make it check if it's a vowel or not?
Reply With Quote
  #2  
Old 04-24-2011, 05:30 AM
Fate's Avatar
Apprentice
 
Join Date: Apr 2005
Posts: 774
Default Re: Help

Write a method that takes an int i as a parameter and run it through a loop that iterates through the string at index i. Then use an if statement to see if the String at index i equals a vowel. If so return true if not return false.
Reply With Quote
  #3  
Old 04-24-2011, 03:35 PM
Member
 
Join Date: Nov 2005
Location: Newcastle, UK.
Posts: 82
Default Re: Help

The String class in Java has the method - charAt(int i)

You can use that in the if statement to see if it equals a vowel. If so, increment the vowel counter.

Something like this;

if(input.charAt(i) == 'a' || input.charAt(i) == 'e' ... i, o, u)
{
increment the vowel counter...
increment the index variable...
}
__________________
Vouches:

Quote:
Originally Posted by I Am The RWT View Post
Vouch for pottworth got him a 50. He paid first.
Quote:
Originally Posted by ChiN RuNz View Post
Vooooooouch for pottworth! Went first and paid fast. Legit and a nice guy too.
Quote:
Originally Posted by Twis7ed147 View Post
Vouch for pottworth, glitches his gears of war 2 account to level 100 he went first. Smooth trade and nice guy.
Reply With Quote
  #4  
Old 04-25-2011, 03:37 AM
Grand Master
 
Join Date: Nov 2005
Location: Perth Amboy, NJ...Sorry no lame joke
Posts: 2,455
Default Re: Help

Thanks guys for the help. I really appreciate it. I'm almost there, but I'm not sure how to make it loop correctly. I'm not getting any errors.

Code:
import java.util.Scanner;

public class two
{
	static double vowel;
	static String word;
	static String word2;
	static int i = 0;
	static int count = -1;

	public static void main(String[] args)
	{
		Scanner keyboard = new Scanner(System.in);

		System.out.println("Enter charcter(s)");
			word = keyboard.nextLine();

		isVowel(word);

		System.out.println("There are/is " + vowel +
						    " vowel(s) in the entry: "
						    + word);
	}

	public static void isVowel(String word2)
	{
		while(count < i)
		{

		if(word2.charAt(i) == 'a' || word2.charAt(i) == 'e' ||
		   word2.charAt(i) == 'i' || word2.charAt(i) == 'o' ||
		   word2.charAt(i) == 'u')
		   	{
		   		vowel++;
		   		i++;
		   		count++;
		   	}
		else
				i++;
				count++;
		}
	}
}
Output:

Enter charcter(s)
aio
There are/is 1.0 vowel(s) in the entry: aio

Last edited by wtp : 04-25-2011 at 03:38 AM.
Reply With Quote
  #5  
Old 04-25-2011, 01:56 PM
Fate's Avatar
Apprentice
 
Join Date: Apr 2005
Posts: 774
Default Re: Help

You should do

Code:
while(count < word2.length()) {


}
That will iterate through the entire string instead of just the first letter.

Last edited by Fate : 04-25-2011 at 08:44 PM.
Reply With Quote
  #6  
Old 04-25-2011, 08:00 PM
Grand Master
 
Join Date: Nov 2005
Location: Perth Amboy, NJ...Sorry no lame joke
Posts: 2,455
Default Re: Help

It's giving me an error when I do that:

cannot find symbol
symbol : variable length
location: class java.lang.String
while(count < word2.length)
^
Reply With Quote
  #7  
Old 04-25-2011, 08:43 PM
Fate's Avatar
Apprentice
 
Join Date: Apr 2005
Posts: 774
Default Re: Help

Quote:
Originally Posted by wtp View Post
It's giving me an error when I do that:

cannot find symbol
symbol : variable length
location: class java.lang.String
while(count < word2.length)
^
Oh sorry its .length(); not just .length;
Reply With Quote
Reply



Cheap RS Gold Store  Runescape Gold

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT +1. The time now is 11:59 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.6.1