Advertisements

User Defined Method

Postby Overcranked » Tue Apr 06, 2010 3:39 pm

Offline
Overcranked
Posts: 2
Joined: Tue Apr 06, 2010 3:28 pm
Location: Upstate NY
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

Postby Overcranked » Wed Apr 07, 2010 4:31 pm

Offline
Overcranked
Posts: 2
Joined: Tue Apr 06, 2010 3:28 pm
Location: Upstate NY
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

Hibernate many-to-many

Postby dragonfly6373 » Thu Nov 29, 2012 10:41 am

Offline
dragonfly6373
Posts: 1
Joined: Thu Nov 29, 2012 10:13 am
Location: HoChiMinh, VietNam
hi everyone.

I have some trouble about this relationship
I have 2 table student and cerfiticate which is many-to-many relationship. How can I list all studen have name like '%an%' and have cerfiticate A, B, C

how can i do that?
Offline
ajitpaswan
Posts: 11
Joined: Mon Dec 24, 2012 2:41 am
Location: India
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class test {
public static void main(String[] args) {
System.out.print("Enter your name and press Enter: ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String name = null;
int length = 0, spaces = 0, vowels = 0, characters = 0, digits = 0;
try {
name = br.readLine();
if(name != null) {
length = name.length();
for(int i = 0; i < length; i++) {
char x = name.charAt(i);
int cast = (int)x;
if(cast == 32) {
spaces = spaces + 1;
} else if(cast >= 48 && cast <= 57) {
digits = digits + 1;
} else if((cast >= 65 && cast <= 90) || (cast >= 97 && cast <= 122)) {
characters = characters + 1;
if(cast == 97 || cast == 101 || cast == 105 || cast == 111 || cast == 117
|| cast == 65 || cast == 69 || cast == 73 || cast == 79 || cast == 85) {
vowels = vowels + 1;
}
}
}
System.out.println("Total spaces are: "+spaces);
System.out.println("Total characters are: "+characters);
System.out.println("Total vowels are: "+vowels);
System.out.println("Total digits are: "+digits);
}
} catch (IOException e) {
System.out.println("Error!");
System.exit(1);
}
}
}

OUTPUT : Enter your name and press Enter: 1ajit 2
Total spaces are: 2
Total characters are: 4
Total vowels are: 2
Total digits are: 2[/b]

Re: User Defined Method

Postby nguyenhai00dn » Tue Apr 02, 2013 12:08 pm

Offline
nguyenhai00dn
Posts: 1
Joined: Tue Apr 02, 2013 11:56 am
Hi Overcranked !

You must declare method 'Method for counting white space' outside method main.

You can test again.

If you are not clear, I will help. Good luck !