www.tutorialspoint.com Forum Index
Register FAQMemberlistUsergroupsTutorials PointLog in
Reply to topic Page 1 of 1
User Defined Method
Author Message
Reply with quote
Post User Defined Method 
Hey All Newbie here, I have a project due in a couple days for school that I need a little help with.
The project is to take a user inputed string and print out how many Characters,Digits,Vowels,whitespace and letters are in the string. I was able to get the string and character length ok, but I need to create Used defined method for all the other parts.

Here is my code so far the problem I am having is the method that I am trying to develop for whitespace counts. I keep compiling a "Illegal start of expression" fault. Can any one simply point me in the right direction please?
This is an intro course so I can not use Regular expression yet.
Thanks
import java.util.*;
public class p6
{



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

{
String x; // declared string variables


System.out.print("Enter a string for character classification: (EOF to end): ");
while (kb.hasNext())//while loop needed to run EOF
{
x = kb.nextLine();// Reads input
System.out.println("The inputLine is " + x.length() + " characters long and contains the following:.");

System.out.print("Enter a string for character classification: (EOF to end): ");}


// Method for counting white space
public int whiteSpace(){

int whiteSpaceCount=0;

for(int i=0;i<s.length();i++)
{
if (x.charAt(i) ==' ');

whiteSpaceCount++;

}
}



}
}


_________________
If at first I don't succeed I'ma try it again and when I do accomplish it I'ma try it again"-Lil Wayne
View user's profile Send private message
Reply with quote
Post  
Whats the point of a forum if it takes over 24 hours to get posts approved?


_________________
If at first I don't succeed I'ma try it again and when I do accomplish it I'ma try it again"-Lil Wayne
View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum