473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

String count with substring

83
Hello
i have a doubt in string count with the sub string.
the main string is "java,mysql,jsp,java,html";
the sub string is like this "java,mysql"

The output is like this
java 2
mysql 1

that is count the no of occureience of the sub string .

how can i do this please help to do this .

Thanks
Sang
Mar 16 '07 #1
60 10387
Ganon11
3,652 Expert 2GB
Could you please explain your problem a bit more fully and post any code you've written or ideas you have?
Mar 16 '07 #2
sang
83
Here is my code
Expand|Select|Wrap|Line Numbers
  1. import java.io.*; 
  2.  import java.util.StringTokenizer; 
  3.  public class strcount
  4.     {      
  5.           public static void main(String arg[]) {      
  6.      String Resume = "java,html,jsp,c,java,dhtml,unix,html";                    String Keyword = "java,html";           
  7.           StringTokenizer st = new      StringTokenizer(Keyword, ",");           
  8.           int count = st.countTokens();           
  9.           int pos = -1;  
  10.      while ( (pos = Resume.indexOf( Keyword, pos + 1 ) ) > -1 )                count++ ;
  11.     System.out.println( "The Keyword" + Keyword + " occurs " + count +               " times" ) ; 
  12.       }   
  13. }
The output is The Keywordjava,html occurs 3 times.

but i want to print java 2 times
html 1 time
Help me please
Thank you
Sang
Mar 17 '07 #3
r035198x
13,262 8TB
Hello
i have a doubt in string count with the sub string.
the main string is "java,mysql,jsp,java,html";
the sub string is like this "java,mysql"

The output is like this
java 2
mysql 1

that is count the no of occureience of the sub string .

how can i do this please help to do this .

Thanks
Sang
You better have a look at regular expressions too.
Mar 17 '07 #4
sang
83
You better have a look at regular expressions too.
please give me the code to solve my problem
Mar 19 '07 #5
sicarie
4,677 Expert Mod 4TB
please give me the code to solve my problem
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR

That is in our Posting Guidelines. Not only that, but we can't help you without more information (which a more specific question would have given us). It depends what you are looking for, and what your regex is currently. Try looking at this tutorial, and see where it gets you. When you have another, more specific question, post it here, and we'll be able to help you better.
Mar 19 '07 #6
sang
83
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidlines.

Then when you are ready post a new question in this thread.

MODERATOR

That is in our Posting Guidelines. Not only that, but we can't help you without more information (which a more specific question would have given us). It depends what you are looking for, and what your regex is currently. Try looking at this tutorial, and see where it gets you. When you have another, more specific question, post it here, and we'll be able to help you better.

Here is my example code i already posted.so please correct my code to solve my problem.
Re: String count with substring
Here is my codeCode:
import java.io.*;
import java.util.StringTokenizer;
public class strcount
{
public static void main(String arg[]) {
String Resume = "java,html,jsp,c,java,dhtml,unix,html"; String Keyword = "java,html";
StringTokenizer st = new StringTokenizer(Keyword, ",");
int count = st.countTokens();
int pos = -1;
while ( (pos = Resume.indexOf( Keyword, pos + 1 ) ) > -1 ) count++ ;
System.out.println( "The Keyword" + Keyword + " occurs " + count + " times" ) ;
}
}



The output is The Keywordjava,html occurs 3 times.

but i want to print java 2 times
html 1 time
Help me please
Thank you
Sang
Mar 19 '07 #7
r035198x
13,262 8TB
Here is my example code i already posted.so please correct my code to solve my problem.
You are better off using regular expressions for this. If you do have to use that tokenizer of yours, then you should use something like

Expand|Select|Wrap|Line Numbers
  1.  
  2. String resume = "java,html,jsp,c,java,dhtml,unix,html";
  3. StringTokenizer st = new StringTokenizer(resume , ",");
  4. int javaCount = 0;
  5. int htmlCount = 0;
  6. while(st.hasMoreTokens()) {
  7.  String s = st.nextToken();
  8.     if(s.equals("java")) {
  9.         javaCount = javaCount  + 1;
  10.     }
  11.     else if(s.equals("html")) {
  12.         htmlCount =  htmlCount + 1;
  13.     }
  14. }
  15.  
Mar 19 '07 #8
sang
83
You are better off using regular expressions for this. If you do have to use that tokenizer of yours, then you should use something like

Expand|Select|Wrap|Line Numbers
  1.  
  2. String resume = "java,html,jsp,c,java,dhtml,unix,html";
  3. StringTokenizer st = new StringTokenizer(resume , ",");
  4. int javaCount = 0;
  5. int htmlCount = 0;
  6. while(st.hasMoreTokens()) {
  7.  String s = st.nextToken();
  8.     if(s.equals("java")) {
  9.         javaCount = javaCount  + 1;
  10.     }
  11.     else if(s.equals("html")) {
  12.         htmlCount =  htmlCount + 1;
  13.     }
  14. }
  15.  
Sorry to distrub you.
I am not finished my work till. From the above coding we don't use the sub string.
My actual requriement is count the no of substrings occurs in the main string.

my actual string is "java,html,unix,java"
my substring is "java,html"

output
java occures in 2 times
html occures in 1 time

the output we count the no of occurence of java and html.

the sub string is not only java and html,anything in the actual string will be given.

So help to do this.Its very urgent please do the needful

Thanks in Advance
Sang
Mar 19 '07 #9
r035198x
13,262 8TB
Sorry to distrub you.
I am not finished my work till. From the above coding we don't use the sub string.
My actual requriement is count the no of substrings occurs in the main string.

my actual string is "java,html,unix,java"
my substring is "java,html"

output
java occures in 2 times
html occures in 1 time

the output we count the no of occurence of java and html.

the sub string is not only java and html,anything in the actual string will be given.

So help to do this.Its very urgent please do the needful

Thanks in Advance
Sang

How about this?

Expand|Select|Wrap|Line Numbers
  1.  
  2. int count = 0;
  3.   int wordLength = word.length();
  4.   for(int i = 0; i < sentence.length(); i = i + wordLength) {
  5.    if(word.equals(sentence.substring(i, i + wordLength))) {
  6.     count++;
  7.    }
  8.   }
  9.  
  10.  
Let me know where you don't understand.
Mar 19 '07 #10
Ganon11
3,652 Expert 2GB
How about this?

Expand|Select|Wrap|Line Numbers
  1.  
  2. int count = 0;
  3.   int wordLength = word.length();
  4.   for(int i = 0; i < sentence.length(); i = i + wordLength) {
  5.    if(word.equals(sentence.substring(i, i + wordLength))) {
  6.     count++;
  7.    }
  8.   }
  9.  
  10.  
Let me know where you don't understand.
I don't think this will work correctly. You are checking every wordLength characters to see if that substring is the word, but the words can be of varying lengths, and you may be checking part of one word and part of another. Why not try:

Expand|Select|Wrap|Line Numbers
  1. int count = 0;
  2. int wordLength = word.length();
  3. for (int i = 0; i < sentence.length() - wordLength; i++) {
  4.    if (word.equals(sentence.substring(i, i + wordLength)
  5.       count++;
  6. }
This will check every possible location of word inside the string.
Mar 19 '07 #11
r035198x
13,262 8TB
I don't think this will work correctly. You are checking every wordLength characters to see if that substring is the word, but the words can be of varying lengths, and you may be checking part of one word and part of another. Why not try:

Expand|Select|Wrap|Line Numbers
  1. int count = 0;
  2. int wordLength = word.length();
  3. for (int i = 0; i < sentence.length() - wordLength; i++) {
  4. if (word.equals(sentence.substring(i, i + wordLength)
  5. count++;
  6. }
This will check every possible location of word inside the string.
Guess I overdid there that time.
Thanks again Ganon.
Mar 19 '07 #12
Ganon11
3,652 Expert 2GB
That's why we're a team :)
Mar 19 '07 #13
r035198x
13,262 8TB
That's why we're a team :)
If you only you guys stay around here more often. Our times seem to be off too.
You always seem to appear around 4pm (for me here).
Mar 19 '07 #14
Ganon11
3,652 Expert 2GB
Right now according to my time, it's 11:22 AM (EST) - what time is it there?

I'm usually on around 3:00 PM (EST) and at least once during the day from Monday-Friday.
Mar 19 '07 #15
r035198x
13,262 8TB
Right now according to my time, it's 11:22 AM (EST) - what time is it there?

I'm usually on around 3:00 PM (EST) and at least once during the day from Monday-Friday.
My time is 5:25 pm now.
Mar 19 '07 #16
Ganon11
3,652 Expert 2GB
And if you see me get on around 4:00 PM your time, that's about 10:00 AM my time - which is when I have a free period sometimes and usually get on TSDN. That would make sense.
Mar 19 '07 #17
sang
83
I don't think this will work correctly. You are checking every wordLength characters to see if that substring is the word, but the words can be of varying lengths, and you may be checking part of one word and part of another. Why not try:

Expand|Select|Wrap|Line Numbers
  1. int count = 0;
  2. int wordLength = word.length();
  3. for (int i = 0; i < sentence.length() - wordLength; i++) {
  4.    if (word.equals(sentence.substring(i, i + wordLength)
  5.       count++;
  6. }
This will check every possible location of word inside the string.
Thank you for your reply

I do that as you give in the above

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class strcount 
  4.  {
  5.       public static void main(String arg[]) {
  6.          try
  7.          {
  8.          String sentence = "java,jsp,c,dhtml,unix";
  9.          String word = "java,html";
  10.          int count=0;
  11.          int wordLength = word.length();
  12.          for(int i = 0; i < sentence.length() - wordLength; i++) {
  13.              if (word.equals(sentence.substring(i, i + wordLength)))
  14.              count++;
  15.          }
  16.          }catch (Exception e) {
  17.              System.out.println("Exception is "+e);
  18.          }
  19.      }
  20.  }
  21.  
But i am confused in how to print the word with their count. I am not able to do that please help me.

Thank you for your kind help
Sang
Mar 20 '07 #18
r035198x
13,262 8TB
Thank you for your reply

I do that as you give in the above

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class strcount 
  4. {
  5.      public static void main(String arg[]) {
  6.          try
  7.          {
  8.          String sentence = "java,jsp,c,dhtml,unix";
  9.          String word = "java,html";
  10.          int count=0;
  11.          int wordLength = word.length();
  12.          for(int i = 0; i < sentence.length() - wordLength; i++) {
  13.              if (word.equals(sentence.substring(i, i + wordLength)))
  14.          count++;
  15.          }
  16.          }catch (Exception e) {
  17.              System.out.println("Exception is "+e);
  18.          }
  19.      }
  20. }
  21.  
But i am confused in how to print the word with their count. I am not able to do that please help me.

Thank you for your kind help
Sang
If you want to check for occurrences java and html, (independanlty) you will have to split the string "java,html" into the separate strings first.
Mar 20 '07 #19
sang
83
If you want to check for occurrences java and html, (independanlty) you will have to split the string "java,html" into the separate strings first.
i split the string like this

int wordLength = word.split(",");

but i don't know how to count this using the split .please do this on the code

Thank you very much
Mar 20 '07 #20
r035198x
13,262 8TB
i split the string like this

int wordLength = word.split(",");

but i don't know how to count this using the split .please do this on the code

Thank you very much
Not very good there. I hope you noticed this.

The split reaturns an array of strings not an int.
You should consider making the word count a function and calling it from the main method for each word you want to count for.
Mar 20 '07 #21
sang
83
Not very good there. I hope you noticed this.

The split reaturns an array of strings not an int.
You should consider making the word count a function and calling it from the main method for each word you want to count for.
sorry sir please give me the code its very urgent.

please do the needfull

Thankyou
Mar 20 '07 #22
r035198x
13,262 8TB
sorry sir please give me the code its very urgent.

please do the needfull

Thankyou
The code is already there and I've posted most of it. Where exactly is your problem now?

Did you change that line for spilt to something like
Expand|Select|Wrap|Line Numbers
  1.  String[] words = word.split(","); 
Mar 20 '07 #23
sang
83
The code is already there and I've posted most of it. Where exactly is your problem now?

Did you change that line for spilt to something like
Expand|Select|Wrap|Line Numbers
  1.  String[] words = word.split(","); 
my program is

Expand|Select|Wrap|Line Numbers
  1.  import java.io.*;
  2.  
  3. public class strcount 
  4.  {
  5.           String sentence = "java,jsp,c,dhtml,unix";
  6.          String word = "java,html";
  7.          int count=0;
  8.          int i;
  9.          String temp[] = word.split(",");
  10.  
  11.          public void st(){
  12.          int wordLength = word.length();
  13.          for( i = 0; i > temp.length - wordLength; i++) {
  14.              if (temp.equals(sentence.substring(i, i+ wordLength)))
  15.              count++;
  16.              System.out.println("the"+i+"array"+count);
  17.          }
  18.     }
  19.     public static void main(String arg[]) {    
  20.             strcount s = new strcount();
  21.             s.st();
  22.      }
  23.  
  24.  }        
  25.  
  26.  
the out put is like this
Expand|Select|Wrap|Line Numbers
  1. the0array0
  2. the1array0
  3. the2array0
  4. the3array0
  5. the4array0
  6. the5array0
  7. the6array0
  8. the7array0
  9. the8array0
  10. the9array0
  11. the10array0
  12. the11array0
  13. the12array0
  14. Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
  15. ex out of range: 22
  16.         at java.lang.String.substring(String.java:1765)
  17.         at strcount.st(strcount.java:14)
  18.         at strcount.main(strcount.java:21)
  19.  
What can i do,i want to calculate the substring count.Please help to do this.
Its very urgent so please give me the code for this program or correct my program.
Thank you very much
Mar 20 '07 #24
r035198x
13,262 8TB
Expand|Select|Wrap|Line Numbers
  1.  
  2. public class strcount {
  3.     public static int countTimes(String sentence, String word){
  4.   int count = 0;
  5.     int wordLength = word.length();
  6.     for(int i = 0; i < sentence.length() - wordLength; i++) {
  7.      if(word.equals(sentence.substring(i, i + wordLength))) {
  8.    count++;
  9.      }
  10.     }
  11.     return count;
  12.  }
  13.  public static void main(String arg[]) {
  14.   String sentence = "java,jsp,c,dhtml,unix";
  15.   String word = "java,html";
  16.   String temp[] = word.split(",");
  17.   for(int i = 0; i < temp.length;i++) {
  18.    System.out.print(temp[i]+" appears : ");
  19.    System.out.print(countTimes(sentence, temp[i]) + " times");
  20.    System.out.println();
  21.   }
  22.  } 
  23.  
  24.  }
  25.  
Notice that html is found because of dhtml. Do you want it like that?
Mar 20 '07 #25
sang
83
The code is already there and I've posted most of it. Where exactly is your problem now?

Did you change that line for spilt to something like
Expand|Select|Wrap|Line Numbers
  1.  String[] words = word.split(","); 
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2.  
  3. public class strcount 
  4.  {
  5.           String sentence = "java,jsp,c,dhtml,unix";
  6.          String word = "java,html";
  7.          int count=0;
  8.          int i;
  9.          String temp[] = word.split(",");
  10.  
  11.          public void st(){
  12.          int wordLength = word.length();
  13.          for( i = 0; i > temp.length - wordLength; i++) {
  14.              if (temp[i].equals(sentence.substring(i, i+ wordLength)))
  15.              count++;
  16.              System.out.println("the"+temp[i]+"count"+i);
  17.          }
  18.     }
  19.     public static void main(String arg[]) {    
  20.             strcount s = new strcount();
  21.             s.st();
  22.      }
  23.  
  24.  }        
  25.  
  26.  
the output is
Expand|Select|Wrap|Line Numbers
  1. thejavacount0
  2. thehtmlcount1
  3. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
  4.         at strcount.st(strcount.java:14)
  5.         at strcount.main(strcount.java:21)
  6.  
but i want to count the no of occurence of word (ie java and html)
please correct the code

Thankyou very much
Mar 20 '07 #26
sang
83
Expand|Select|Wrap|Line Numbers
  1.  
  2. public class strcount {
  3.     public static int countTimes(String sentence, String word){
  4.   int count = 0;
  5.     int wordLength = word.length();
  6.     for(int i = 0; i < sentence.length() - wordLength; i++) {
  7.      if(word.equals(sentence.substring(i, i + wordLength))) {
  8.    count++;
  9.      }
  10.     }
  11.     return count;
  12.  }
  13.  public static void main(String arg[]) {
  14.   String sentence = "java,jsp,c,dhtml,unix";
  15.   String word = "java,html";
  16.   String temp[] = word.split(",");
  17.   for(int i = 0; i < temp.length;i++) {
  18.    System.out.print(temp[i]+" appears : ");
  19.    System.out.print(countTimes(sentence, temp[i]) + " times");
  20.    System.out.println();
  21.   }
  22.  } 
  23.  
  24.  }
  25.  
Notice that html is found because of dhtml. Do you want it like that?
Thank you very much for your kind help
Mar 20 '07 #27
Ganon11
3,652 Expert 2GB
The split method returns a String array, correct? And you want to find the occurances of each word in this array? Then you can use a loop to perform this check in every line. As the final statement in this loop, put a println() call to output the word and count.
Mar 20 '07 #28
sang
83
Expand|Select|Wrap|Line Numbers
  1.  
  2. public class strcount {
  3.     public static int countTimes(String sentence, String word){
  4.   int count = 0;
  5.     int wordLength = word.length();
  6.     for(int i = 0; i < sentence.length() - wordLength; i++) {
  7.      if(word.equals(sentence.substring(i, i + wordLength))) {
  8.    count++;
  9.      }
  10.     }
  11.     return count;
  12.  }
  13.  public static void main(String arg[]) {
  14.   String sentence = "java,jsp,c,dhtml,unix";
  15.   String word = "java,html";
  16.   String temp[] = word.split(",");
  17.   for(int i = 0; i < temp.length;i++) {
  18.    System.out.print(temp[i]+" appears : ");
  19.    System.out.print(countTimes(sentence, temp[i]) + " times");
  20.    System.out.println();
  21.   }
  22.  } 
  23.  
  24.  }
  25.  
Notice that html is found because of dhtml. Do you want it like that?
Hello Sir
I used the above code in DB to count the no of keyword matches in the resume. The Resume is stored in one table and the Key word is on the another table.i do it but one error will be occur. i will give that code please correct it. Because it is very urgent.So i finished it
The code is
Expand|Select|Wrap|Line Numbers
  1. package ic.bo;
  2.  
  3. import java.io.*;
  4. import java.sql.*;
  5. import ic.bo.*;
  6. import ic.db.DBConnection;
  7. //import java.util.StringTokenizer;
  8.  
  9. public class KeywordCount {
  10.     private Connection dbConnection = null;    
  11.     public String errDesc;    
  12.  
  13.     public KeywordCount() throws SQLException {
  14.         DBConnection db = new DBConnection();
  15.         dbConnection = db.getDBConnection();
  16.         if (dbConnection == null) {
  17.             throw new SQLException("Connection Error");
  18.         }
  19.     }        
  20.  
  21.     public void closeConnection() {
  22.         try{
  23.             dbConnection.close();
  24.         }catch(Exception e) {
  25.         }
  26.      }
  27.      public void countKeyword() {
  28.          try{
  29.              String sql1 = "select JobRefNo,ifnull(Keywords,' ') from JOB_ORDER where Status<>'Expired' and ValidUpto >= sysdate()";
  30.              Statement stm1 = dbConnection.createStatement();
  31.              ResultSet rs1 = null;
  32.              rs1 = stm1.executeQuery(sql1);            
  33.  
  34.             while(rs1.next()) {
  35.                 String sql2 = "select UserId from JOB_APPLICATION where  NoOfMatch=-1 and JobRefNo=" +rs1.getInt(1);
  36.                 Statement stm2 = dbConnection.createStatement();
  37.                 ResultSet rs2 = null;
  38.                 rs2 = stm2.executeQuery(sql2);
  39.                 while(rs2.next()) {
  40.                   try
  41.                     {
  42.                     String sql3 = "select TxtResume from CAN_RESUME where UserId="+rs2.getInt(1);
  43.                     Statement stm3 = dbConnection.createStatement();
  44.                     ResultSet rs3 = null;
  45.                     rs3 = stm3.executeQuery(sql3);
  46.                     rs3.next();
  47.                     String TxtResume=rs3.getString(1);
  48.                     String Keywords=rs1.getString(2);
  49.                     String temp[] = Keywords.split(",");
  50.                     for(int i = 0; i < temp.length;i++) {
  51.                     System.out.print(temp[i]+" appears : ");
  52.                     System.out.print(countTimes(TxtResume, temp[i]) + " times");
  53.                     System.out.println();
  54.                     }
  55.                     } catch (Exception e) {
  56.                     System.out.println("DB error while execute the SQL " + e);
  57.                     }
  58.             }
  59.             rs2.close();
  60.                 stm2.close();
  61.             }
  62.             }catch (Exception e) {
  63.                     System.out.println("DB error while execute the SQL " + e);
  64.                     }
  65.  
  66.         public void countTimes(String TxtResume ,String Keywords){
  67.                     try
  68.                     {
  69.                     int KeywordsLength = Keywords.length();
  70.                     for(int i = 0; i < TxtResume.length() - KeywordsLength; i++) {
  71.                     if(Keywords.equals(TxtResume.substring(i, i + KeywordsLength))) {
  72.                     count++;
  73.                         }
  74.                     }
  75.                     return count;
  76.                     rs1.close();
  77.                     stm1.close();
  78.             } catch (Exception e) {
  79.                 System.out.println("DB error while execute the SQL " + e);
  80.                 return;
  81.             }
  82.         }
  83.     }
  84.     public static void main(String arg[]) {
  85.         try
  86.         {
  87.         KeywordCount key = new KeywordCount();
  88.         key.countKeyword();
  89.         key.countTimes();
  90.         } catch(Exception e) {
  91.         }
  92.     }
  93. }
  94.  
  95.  
The Error is D:\epc\delv\WEB-INF\classes\ic\bo\KeywordCount.java:66: illegal start of expression
public void countTimes(String TxtResume ,String Keywords){
So please help to solve the problem

Thanks and Regards
Sang
Mar 23 '07 #29
r035198x
13,262 8TB
Hello Sir
I used the above code in DB to count the no of keyword matches in the resume. The Resume is stored in one table and the Key word is on the another table.i do it but one error will be occur. i will give that code please correct it. Because it is very urgent.So i finished it
The code is
Expand|Select|Wrap|Line Numbers
  1. package ic.bo;
  2.  
  3. import java.io.*;
  4. import java.sql.*;
  5. import ic.bo.*;
  6. import ic.db.DBConnection;
  7. //import java.util.StringTokenizer;
  8.  
  9. public class KeywordCount {
  10.     private Connection dbConnection = null;    
  11.     public String errDesc;    
  12.  
  13.     public KeywordCount() throws SQLException {
  14.         DBConnection db = new DBConnection();
  15.         dbConnection = db.getDBConnection();
  16.         if (dbConnection == null) {
  17.             throw new SQLException("Connection Error");
  18.         }
  19.     }        
  20.  
  21.     public void closeConnection() {
  22.         try{
  23.             dbConnection.close();
  24.         }catch(Exception e) {
  25.         }
  26.      }
  27.      public void countKeyword() {
  28.          try{
  29.              String sql1 = "select JobRefNo,ifnull(Keywords,' ') from JOB_ORDER where Status<>'Expired' and ValidUpto >= sysdate()";
  30.              Statement stm1 = dbConnection.createStatement();
  31.              ResultSet rs1 = null;
  32.              rs1 = stm1.executeQuery(sql1);            
  33.  
  34.             while(rs1.next()) {
  35.                 String sql2 = "select UserId from JOB_APPLICATION where NoOfMatch=-1 and JobRefNo=" +rs1.getInt(1);
  36.                 Statement stm2 = dbConnection.createStatement();
  37.                 ResultSet rs2 = null;
  38.                 rs2 = stm2.executeQuery(sql2);
  39.                 while(rs2.next()) {
  40.              try
  41.                     {
  42.                     String sql3 = "select TxtResume from CAN_RESUME where UserId="+rs2.getInt(1);
  43.                     Statement stm3 = dbConnection.createStatement();
  44.                     ResultSet rs3 = null;
  45.                     rs3 = stm3.executeQuery(sql3);
  46.                     rs3.next();
  47.                     String TxtResume=rs3.getString(1);
  48.                     String Keywords=rs1.getString(2);
  49.                     String temp[] = Keywords.split(",");
  50.                     for(int i = 0; i < temp.length;i++) {
  51.                     System.out.print(temp[i]+" appears : ");
  52.                     System.out.print(countTimes(TxtResume, temp[i]) + " times");
  53.                     System.out.println();
  54.                     }
  55.                     } catch (Exception e) {
  56.                     System.out.println("DB error while execute the SQL " + e);
  57.                     }
  58.             }
  59.             rs2.close();
  60.                 stm2.close();
  61.             }
  62.             }catch (Exception e) {
  63.                     System.out.println("DB error while execute the SQL " + e);
  64.                     }
  65.  
  66.         public void countTimes(String TxtResume ,String Keywords){
  67.                     try
  68.                     {
  69.                     int KeywordsLength = Keywords.length();
  70.                     for(int i = 0; i < TxtResume.length() - KeywordsLength; i++) {
  71.                     if(Keywords.equals(TxtResume.substring(i, i + KeywordsLength))) {
  72.                     count++;
  73.                         }
  74.                     }
  75.                     return count;
  76.                     rs1.close();
  77.                     stm1.close();
  78.             } catch (Exception e) {
  79.                 System.out.println("DB error while execute the SQL " + e);
  80.                 return;
  81.             }
  82.         }
  83.     }
  84.     public static void main(String arg[]) {
  85.         try
  86.         {
  87.         KeywordCount key = new KeywordCount();
  88.         key.countKeyword();
  89.         key.countTimes();
  90.         } catch(Exception e) {
  91.         }
  92.     }
  93. }
  94.  
  95.  
The Error is D:\epc\delv\WEB-INF\classes\ic\bo\KeywordCount.java:66: illegal start of expression
public void countTimes(String TxtResume ,String Keywords){
So please help to solve the problem

Thanks and Regards
Sang
1.)You don't have to post all your code like this
2.)You have put the countTimes method inside another method. This is not allowed and is the reason for the error. Pluck it out so that no method is inside another method.
3.) When handling exceptions do not use
Expand|Select|Wrap|Line Numbers
  1.  catch(Exception e) { 
  2. }
  3.  
This hides the exception when it occurs so you don't see it. Ideally you should want to be able to know if your code is throwing an exception.
Mar 23 '07 #30
sang
83
1.)You don't have to post all your code like this
2.)You have put the countTimes method inside another method. This is not allowed and is the reason for the error. Pluck it out so that no method is inside another method.
3.) When handling exceptions do not use
Expand|Select|Wrap|Line Numbers
  1.  catch(Exception e) { 
  2. }
  3.  
This hides the exception when it occurs so you don't see it. Ideally you should want to be able to know if your code is throwing an exception.
Yes I done your advice

The program is Complie and run Successfully but it does not return any output
please help to do this

Expand|Select|Wrap|Line Numbers
  1. public class KeywordCount {
  2.  public void countKeyword() {
  3.          try{
  4.              String sql1 = "select JobRefNo,ifnull(Keywords,' ') from JOB_ORDER where Status<>'Expired' and ValidUpto >= sysdate()";
  5.              Statement stm1 = dbConnection.createStatement();
  6.              ResultSet rs1 = null;
  7.              rs1 = stm1.executeQuery(sql1);            
  8.  
  9.             while(rs1.next()) {
  10.                 String sql2 = "select UserId from JOB_APPLICATION where  NoOfMatch=-1 and JobRefNo=" +rs1.getInt(1);
  11.                 Statement stm2 = dbConnection.createStatement();
  12.                 ResultSet rs2 = null;
  13.                 rs2 = stm2.executeQuery(sql2);
  14.                 while(rs2.next()) {
  15.                   try {
  16.                     String sql3 = "select TxtResume from CAN_RESUME where UserId="+rs2.getInt(1);
  17.                     Statement stm3 = dbConnection.createStatement();
  18.                     ResultSet rs3 = null;
  19.                     rs3 = stm3.executeQuery(sql3);
  20.                     rs3.next();
  21.                     String TxtResume=rs3.getString(1);
  22.                     String Keywords=rs1.getString(2);
  23.                     String temp[] = Keywords.split(",");
  24.                     for(int i = 0; i < temp.length;i++) {
  25.                     System.out.print(temp[i]+" appears : ");
  26.                     //System.out.print(countTimes(TxtResume, temp[i]) + " times");
  27.  
  28.                     }
  29.                     } catch (Exception e) {
  30.                     System.out.println("DB error while execute the SQL " + e);
  31.                     }
  32.             }
  33.             rs2.close();
  34.                 stm2.close();
  35.             }
  36.             }catch (Exception e) {
  37.                     System.out.println("DB error while execute the SQL " + e);
  38.                     }
  39.      }            
  40.         public int countTimes(InputStream in ,String Keywords1){
  41.             DataInputStream din = new DataInputStream(in);
  42.             String line = null;
  43.             int count=0;
  44.                     try    {
  45.                         while((line=din.readLine()) != null){
  46.                         String line2 = line.toLowerCase();
  47.                         int KeywordsLength = Keywords1.length();
  48.                         for(int i = 0; i < line2.length() - KeywordsLength; i++) {
  49.                         if(Keywords1.equals(line2.substring(i, i + KeywordsLength))) {
  50.                         count++;
  51.                         System.out.println("the count is "+count);
  52.                         }
  53.                     }
  54.                         }
  55.                     return count;
  56.                     //
  57.                     //rs1.close();
  58.                     //stm1.close();
  59.             } catch (Exception e1) {
  60.                 System.out.println("DB error while execute the SQL " + e1);
  61.                 return -1;
  62.             }
  63.         }
  64.     public static void main(String arg[]) {
  65.         try
  66.         {
  67.         KeywordCount key = new KeywordCount();
  68.         key.countKeyword();
  69.         //key.countTimes();
  70.         } catch(Exception e) {
  71.             System.out.println("Exception is"+e);
  72.         }
  73.     }
  74. }
  75.  
please help to do this

Thankyou
Sang
Mar 23 '07 #31
r035198x
13,262 8TB
Yes I done your advice

The program is Complie and run Successfully but it does not return any output
please help to do this

Expand|Select|Wrap|Line Numbers
  1. public class KeywordCount {
  2. public void countKeyword() {
  3.          try{
  4.              String sql1 = "select JobRefNo,ifnull(Keywords,' ') from JOB_ORDER where Status<>'Expired' and ValidUpto >= sysdate()";
  5.              Statement stm1 = dbConnection.createStatement();
  6.              ResultSet rs1 = null;
  7.              rs1 = stm1.executeQuery(sql1);            
  8.  
  9.             while(rs1.next()) {
  10.                 String sql2 = "select UserId from JOB_APPLICATION where NoOfMatch=-1 and JobRefNo=" +rs1.getInt(1);
  11.                 Statement stm2 = dbConnection.createStatement();
  12.                 ResultSet rs2 = null;
  13.                 rs2 = stm2.executeQuery(sql2);
  14.                 while(rs2.next()) {
  15.              try {
  16.                     String sql3 = "select TxtResume from CAN_RESUME where UserId="+rs2.getInt(1);
  17.                     Statement stm3 = dbConnection.createStatement();
  18.                     ResultSet rs3 = null;
  19.                     rs3 = stm3.executeQuery(sql3);
  20.                     rs3.next();
  21.                     String TxtResume=rs3.getString(1);
  22.                     String Keywords=rs1.getString(2);
  23.                     String temp[] = Keywords.split(",");
  24.                     for(int i = 0; i < temp.length;i++) {
  25.                     System.out.print(temp[i]+" appears : ");
  26.                     //System.out.print(countTimes(TxtResume, temp[i]) + " times");
  27.  
  28.                     }
  29.                     } catch (Exception e) {
  30.                     System.out.println("DB error while execute the SQL " + e);
  31.                     }
  32.             }
  33.             rs2.close();
  34.                 stm2.close();
  35.             }
  36.             }catch (Exception e) {
  37.                     System.out.println("DB error while execute the SQL " + e);
  38.                     }
  39.      }            
  40.         public int countTimes(InputStream in ,String Keywords1){
  41.             DataInputStream din = new DataInputStream(in);
  42.             String line = null;
  43.             int count=0;
  44.                     try    {
  45.                         while((line=din.readLine()) != null){
  46.                         String line2 = line.toLowerCase();
  47.                         int KeywordsLength = Keywords1.length();
  48.                         for(int i = 0; i < line2.length() - KeywordsLength; i++) {
  49.                         if(Keywords1.equals(line2.substring(i, i + KeywordsLength))) {
  50.                         count++;
  51.                         System.out.println("the count is "+count);
  52.                         }
  53.                     }
  54.                         }
  55.                     return count;
  56.                     //
  57.                     //rs1.close();
  58.                     //stm1.close();
  59.             } catch (Exception e1) {
  60.                 System.out.println("DB error while execute the SQL " + e1);
  61.                 return -1;
  62.             }
  63.         }
  64.     public static void main(String arg[]) {
  65.         try
  66.         {
  67.         KeywordCount key = new KeywordCount();
  68.         key.countKeyword();
  69.         //key.countTimes();
  70.         } catch(Exception e) {
  71.             System.out.println("Exception is"+e);
  72.         }
  73.     }
  74. }
  75.  
please help to do this

Thankyou
Sang
What output do you want it to give?
Mar 23 '07 #32
sang
83
What output do you want it to give?
The resume and keywords are taken from different table.
The program is check whether the keywords are in the resume, if the keywords are present Count the each keywords.

In the out put it will be return

Keyword How many times present

for example the keyword is java and it present 3 times

The output is

java ===>3 times

Thankyou
Sang
Mar 23 '07 #33
r035198x
13,262 8TB
The resume and keywords are taken from different table.
The program is check whether the keywords are in the resume, if the keywords are present Count the each keywords.

In the out put it will be return

Keyword How many times present

for example the keyword is java and it present 3 times

The output is

java ===>3 times

Thankyou
Sang
Debug it with println statements to verify that each statement is doing what you think it is doing.
Mar 23 '07 #34
sang
83
Debug it with println statements to verify that each statement is doing what you think it is doing.
My problem is
Expand|Select|Wrap|Line Numbers
  1. public void countKeyword() {
  2.          try{
  3.              String sql1 = "select JobRefNo,ifnull(Keywords,' ') from JOB_ORDER where Status<>'Expired' and ValidUpto >= sysdate()";
  4.              Statement stm1 = dbConnection.createStatement();
  5.              ResultSet rs1 = null;
  6.              rs1 = stm1.executeQuery(sql1);            
  7.  
  8.             while(rs1.next()) {
  9.                 String sql2 = "select UserId from JOB_APPLICATION where  NoOfMatch=-1 and JobRefNo=" +rs1.getInt(1);
  10.                 Statement stm2 = dbConnection.createStatement();
  11.                 ResultSet rs2 = null;
  12.                 rs2 = stm2.executeQuery(sql2);
  13.                 while(rs2.next()) {
  14.                   try {
  15.  
  16.                     String sql3 = "select TxtResume from CAN_RESUME where TxtStatus=1 and UserId="+rs2.getInt(1);                    Statement stm3 = dbConnection.createStatement();
  17.                     ResultSet rs3 = null;
  18.                     rs3 = stm3.executeQuery(sql3);
  19.                     rs3.next();
  20.                     String TxtResume=rs3.getString(1);
  21.                     String Keywords=rs1.getString(2);
  22.                     String temp[] = Keywords.split(",");
  23.         //            countKeyword ct = new countKeyword();
  24.                     for(int i = 0; i < temp.length;i++) {
  25.                     System.out.print(temp[i]+" appears : ");
  26.                     System.out.print(countTimes(TxtResume, temp[i]) + " times");
  27.                     }
  28.                     } catch (Exception e) {
  29.                     System.out.println("DB error while execute the SQL " + e);
  30.                     }
  31.             }
  32.             rs2.close();
  33.                 stm2.close();
  34.             }
  35.             }catch (Exception e) {
  36.                     System.out.println("DB error while execute the SQL " + e);
  37.                     }            
  38.      }
  39.         public int countTimes(InputStream in ,String Keywords1){
  40.             DataInputStream din = new DataInputStream(in);
  41.             String line = null;
  42.             int count=0;
  43.                     try    {
  44.                         while((line=din.readLine()) != null){
  45.                         String line2 = line.toLowerCase();
  46.                         int KeywordsLength = Keywords1.length();
  47.                         for(int i = 0; i < line2.length() - KeywordsLength; i++) {
  48.                         if(Keywords1.equals(line2.substring(i, i + KeywordsLength))) {
  49.                         count++;
  50.                         //System.out.println("the count is "+count);
  51.                         }
  52.                     }
  53.                         }
  54.                     return count;
  55.                     //
  56.                     //rs1.close();
  57.                     //stm1.close();
  58.             } catch (Exception e1) {
  59.                 System.out.println("DB error while execute the SQL " + e1);
  60.                 return -1;
  61.             }
  62.         }
  63.  
In this how can i call the countTimes() in the countKeyword()

I call this using
System.out.print(countTimes(TxtResume, temp[i]) + " times");

but erorr is occured in the above line

D:\epc\delv\WEB-INF\classes\ic\bo\KeywordCount.java:51: countTimes(java.io.Input
Stream,java.lang.String) in ic.bo.KeywordCount cannot be applied to (java.lang.S
tring,java.lang.String)
System.out.print(countTimes(TxtResume, t
emp[i]) + " times");

please help to do this
Thanks and regards
Sang
Mar 26 '07 #35
r035198x
13,262 8TB
My problem is
Expand|Select|Wrap|Line Numbers
  1. public void countKeyword() {
  2.          try{
  3.              String sql1 = "select JobRefNo,ifnull(Keywords,' ') from JOB_ORDER where Status<>'Expired' and ValidUpto >= sysdate()";
  4.              Statement stm1 = dbConnection.createStatement();
  5.              ResultSet rs1 = null;
  6.              rs1 = stm1.executeQuery(sql1);            
  7.  
  8.             while(rs1.next()) {
  9.                 String sql2 = "select UserId from JOB_APPLICATION where NoOfMatch=-1 and JobRefNo=" +rs1.getInt(1);
  10.                 Statement stm2 = dbConnection.createStatement();
  11.                 ResultSet rs2 = null;
  12.                 rs2 = stm2.executeQuery(sql2);
  13.                 while(rs2.next()) {
  14.              try {
  15.  
  16.                     String sql3 = "select TxtResume from CAN_RESUME where TxtStatus=1 and UserId="+rs2.getInt(1);                    Statement stm3 = dbConnection.createStatement();
  17.                     ResultSet rs3 = null;
  18.                     rs3 = stm3.executeQuery(sql3);
  19.                     rs3.next();
  20.                     String TxtResume=rs3.getString(1);
  21.                     String Keywords=rs1.getString(2);
  22.                     String temp[] = Keywords.split(",");
  23.         //            countKeyword ct = new countKeyword();
  24.                     for(int i = 0; i < temp.length;i++) {
  25.                     System.out.print(temp[i]+" appears : ");
  26.                     System.out.print(countTimes(TxtResume, temp[i]) + " times");
  27.                     }
  28.                     } catch (Exception e) {
  29.                     System.out.println("DB error while execute the SQL " + e);
  30.                     }
  31.             }
  32.             rs2.close();
  33.                 stm2.close();
  34.             }
  35.             }catch (Exception e) {
  36.                     System.out.println("DB error while execute the SQL " + e);
  37.                     }            
  38.      }
  39.         public int countTimes(InputStream in ,String Keywords1){
  40.             DataInputStream din = new DataInputStream(in);
  41.             String line = null;
  42.             int count=0;
  43.                     try    {
  44.                         while((line=din.readLine()) != null){
  45.                         String line2 = line.toLowerCase();
  46.                         int KeywordsLength = Keywords1.length();
  47.                         for(int i = 0; i < line2.length() - KeywordsLength; i++) {
  48.                         if(Keywords1.equals(line2.substring(i, i + KeywordsLength))) {
  49.                         count++;
  50.                         //System.out.println("the count is "+count);
  51.                         }
  52.                     }
  53.                         }
  54.                     return count;
  55.                     //
  56.                     //rs1.close();
  57.                     //stm1.close();
  58.             } catch (Exception e1) {
  59.                 System.out.println("DB error while execute the SQL " + e1);
  60.                 return -1;
  61.             }
  62.         }
  63.  
In this how can i call the countTimes() in the countKeyword()

I call this using
System.out.print(countTimes(TxtResume, temp[i]) + " times");

but erorr is occured in the above line

D:\epc\delv\WEB-INF\classes\ic\bo\KeywordCount.java:51: countTimes(java.io.Input
Stream,java.lang.String) in ic.bo.KeywordCount cannot be applied to (java.lang.S
tring,java.lang.String)
System.out.print(countTimes(TxtResume, t
emp[i]) + " times");

please help to do this
Thanks and regards
Sang
Your arguments are not matching the countTimes signature. Look at the countTimes method again and understand what each parameter is doing in the method.
Mar 26 '07 #36
sang
83
Your arguments are not matching the countTimes signature. Look at the countTimes method again and understand what each parameter is doing in the method.
Thankyou very much I solved that problem. but i have another error.
That is DB error please see the code and give the suggesstion to solve it
Expand|Select|Wrap|Line Numbers
  1. public void countKeyword() {
  2.          try{
  3.              String sql1 = "select JobRefNo,ifnull(Keywords,' ') from JOB_ORDER where Status<>'Expired' and ValidUpto >= sysdate()";
  4.              Statement stm1 = dbConnection.createStatement();
  5.              ResultSet rs1 = null;
  6.              rs1 = stm1.executeQuery(sql1);            
  7.  
  8.             while(rs1.next()) {
  9.                 String sql2 = "select UserId from JOB_APPLICATION where  NoOfMatch=-1 and JobRefNo=" +rs1.getInt(1);
  10.                 Statement stm2 = dbConnection.createStatement();
  11.                 ResultSet rs2 = null;
  12.                 rs2 = stm2.executeQuery(sql2);
  13.                 while(rs2.next()) {
  14.                   try {
  15.  
  16.                     String sql3 = "select TxtResume from CAN_RESUME where TxtStatus=1 and UserId="+rs2.getInt(1);                    Statement stm3 = dbConnection.createStatement();
  17.                     ResultSet rs3 = null;
  18.                     rs3 = stm3.executeQuery(sql3);
  19.                     rs3.next();
  20.                     String TxtResume=rs3.getString(1);
  21.                     String Keywords=rs1.getString(2);
  22.                     String temp[] = Keywords.split(",");
  23.         //            countKeyword ct = new countKeyword();
  24.                     for(int i = 0; i < temp.length;i++) {
  25.                     System.out.print(temp[i]+" appears : ");
  26.                     System.out.print(countTimes(TxtResume, temp[i]) + " times");
  27.                     System.out.println();
  28.                     }
  29.                     } catch (Exception e) {
  30.                     System.out.println("DB error while execute the SQL " + e);
  31.                     }
  32.             }
  33.             rs2.close();
  34.                 stm2.close();
  35.             }
  36.             }catch (Exception e) {
  37.                     System.out.println("DB error while execute the SQL " + e);
  38.                     }            
  39.      }
  40.         public int countTimes(String TxtResume ,String Keywords){
  41.             //DataInputStream din = new DataInputStream(in);
  42.             //String line = null;
  43.             int count=0;
  44.                     try    {
  45.                         //while((line=din.readLine()) != null){
  46.                         //String line2 = line.toLowerCase();
  47.                         int KeywordsLength = Keywords.length();
  48.                         for(int i = 0; i < TxtResume.length() - KeywordsLength; i++) {
  49.                         if(Keywords.equals(TxtResume.substring(i, i + KeywordsLength))) {
  50.                         count++;
  51.                         }
  52.                     }
  53.  
  54.                     return count;
  55.                     //
  56.                     //rs1.close();
  57.                     //stm1.close();
  58.             } catch (Exception e1) {
  59.                 System.out.println("DB error while execute the SQL " + e1);
  60.                 return -1;
  61.             }
  62.         }
  63.  
the error is
Expand|Select|Wrap|Line Numbers
  1. Cummins appears : DB error while execute the SQL java.lang.NullPointerException
  2. -1 times
  3. Service appears : DB error while execute the SQL java.lang.NullPointerException
  4. -1 times
  5.  
please help to slove this error
Thankyou
Sang
Mar 26 '07 #37
r035198x
13,262 8TB
Thankyou very much I solved that problem. but i have another error.
That is DB error please see the code and give the suggesstion to solve it
Expand|Select|Wrap|Line Numbers
  1. public void countKeyword() {
  2.          try{
  3.              String sql1 = "select JobRefNo,ifnull(Keywords,' ') from JOB_ORDER where Status<>'Expired' and ValidUpto >= sysdate()";
  4.              Statement stm1 = dbConnection.createStatement();
  5.              ResultSet rs1 = null;
  6.              rs1 = stm1.executeQuery(sql1);            
  7.  
  8.             while(rs1.next()) {
  9.                 String sql2 = "select UserId from JOB_APPLICATION where NoOfMatch=-1 and JobRefNo=" +rs1.getInt(1);
  10.                 Statement stm2 = dbConnection.createStatement();
  11.                 ResultSet rs2 = null;
  12.                 rs2 = stm2.executeQuery(sql2);
  13.                 while(rs2.next()) {
  14.              try {
  15.  
  16.                     String sql3 = "select TxtResume from CAN_RESUME where TxtStatus=1 and UserId="+rs2.getInt(1);                    Statement stm3 = dbConnection.createStatement();
  17.                     ResultSet rs3 = null;
  18.                     rs3 = stm3.executeQuery(sql3);
  19.                     rs3.next();
  20.                     String TxtResume=rs3.getString(1);
  21.                     String Keywords=rs1.getString(2);
  22.                     String temp[] = Keywords.split(",");
  23.         //            countKeyword ct = new countKeyword();
  24.                     for(int i = 0; i < temp.length;i++) {
  25.                     System.out.print(temp[i]+" appears : ");
  26.                     System.out.print(countTimes(TxtResume, temp[i]) + " times");
  27.                     System.out.println();
  28.                     }
  29.                     } catch (Exception e) {
  30.                     System.out.println("DB error while execute the SQL " + e);
  31.                     }
  32.             }
  33.             rs2.close();
  34.                 stm2.close();
  35.             }
  36.             }catch (Exception e) {
  37.                     System.out.println("DB error while execute the SQL " + e);
  38.                     }            
  39.      }
  40.         public int countTimes(String TxtResume ,String Keywords){
  41.             //DataInputStream din = new DataInputStream(in);
  42.             //String line = null;
  43.             int count=0;
  44.                     try    {
  45.                         //while((line=din.readLine()) != null){
  46.                         //String line2 = line.toLowerCase();
  47.                         int KeywordsLength = Keywords.length();
  48.                         for(int i = 0; i < TxtResume.length() - KeywordsLength; i++) {
  49.                         if(Keywords.equals(TxtResume.substring(i, i + KeywordsLength))) {
  50.                         count++;
  51.                         }
  52.                     }
  53.  
  54.                     return count;
  55.                     //
  56.                     //rs1.close();
  57.                     //stm1.close();
  58.             } catch (Exception e1) {
  59.                 System.out.println("DB error while execute the SQL " + e1);
  60.                 return -1;
  61.             }
  62.         }
  63.  
the error is
Expand|Select|Wrap|Line Numbers
  1. Cummins appears : DB error while execute the SQL java.lang.NullPointerException
  2. -1 times
  3. Service appears : DB error while execute the SQL java.lang.NullPointerException
  4. -1 times
  5.  
please help to slove this error
Thankyou
Sang
Check the line number for the exception and locate it in your code
Mar 26 '07 #38
sang
83
Check the line number for the exception and locate it in your code
Thanyou for your kind help

I solved the problem and my program is excuted well. But the count will reduce the count by one. my keyword appears actually 3 times but in the output will be printed as 2 times appears.
I am trying to finish that problem if you have any suggestion please give me to solve the problem

I once again Say Thankyou for your timely help.

Thankyou VeryMuch
Sang
Mar 26 '07 #39
r035198x
13,262 8TB
Thanyou for your kind help

I solved the problem and my program is excuted well. But the count will reduce the count by one. my keyword appears actually 3 times but in the output will be printed as 2 times appears.
I am trying to finish that problem if you have any suggestion please give me to solve the problem

I once again Say Thankyou for your timely help.

Thankyou VeryMuch
Sang
Try changing your for header to

Expand|Select|Wrap|Line Numbers
  1.  
  2. for(int i = 0; i < (TxtResume.length() - KeywordsLength) + 1; i++) 
  3.  
Mar 26 '07 #40
sang
83
Try changing your for header to

Expand|Select|Wrap|Line Numbers
  1.  
  2. for(int i = 0; i < (TxtResume.length() - KeywordsLength) + 1; i++) 
  3.  
I tried this one but there is no changes in my output.

Thankyou for your kind help,
Sang
Mar 27 '07 #41
r035198x
13,262 8TB
I tried this one but there is no changes in my output.

Thankyou for your kind help,
Sang
You can always solve the problem by using return count + 1; but I'd rather you check first that the output you are getting is really not what it should be.
Mar 27 '07 #42
sang
83
You can always solve the problem by using return count + 1; but I'd rather you check first that the output you are getting is really not what it should be.
Thankyou very much for your help
Mar 27 '07 #43
sang
83
Expand|Select|Wrap|Line Numbers
  1.  
  2. public class strcount {
  3.     public static int countTimes(String sentence, String word){
  4.   int count = 0;
  5.     int wordLength = word.length();
  6.     for(int i = 0; i < sentence.length() - wordLength; i++) {
  7.      if(word.equals(sentence.substring(i, i + wordLength))) {
  8.    count++;
  9.      }
  10.     }
  11.     return count;
  12.  }
  13.  public static void main(String arg[]) {
  14.   String sentence = "java,jsp,c,dhtml,unix";
  15.   String word = "java,html";
  16.   String temp[] = word.split(",");
  17.   for(int i = 0; i < temp.length;i++) {
  18.    System.out.print(temp[i]+" appears : ");
  19.    System.out.print(countTimes(sentence, temp[i]) + " times");
  20.    System.out.println();
  21.   }
  22.  } 
  23.  
  24.  }
  25.  
Notice that html is found because of dhtml. Do you want it like that?
Hello Sir

Another help to do the above program in single method.
In the above program the count is seperate function and it is call on the main.
but i want to all this on main there is no other function call.

I will try this one but my output is 0 please help to do this

Expand|Select|Wrap|Line Numbers
  1. public class strcount
  2.  {
  3.     public static void main(String arg[]) {
  4.     String resume = "java,html,jsp,c,java,dhtml,unix,html";
  5.      String word = "java,jsp,html";
  6.     String temp[] = word.split(",");
  7.         for(int i = 0; i < temp.length;i++) {
  8.          System.out.println(temp[i]+" appears : ");
  9.         }
  10.         int count = 0;
  11.     int wordLength = word.length();
  12.     for(int j = 0; j < resume.length() - wordLength; j++) {
  13.      if(word.equals(resume.substring(j, j + wordLength))) {
  14.    count++;
  15.    //System.out.print((temp[i]),count);
  16.      }
  17.     }
  18.     System.out.println(count);
  19.     //return count;
  20.     }
  21.  }
  22.  
output is like this
Expand|Select|Wrap|Line Numbers
  1. java appears :
  2. jsp appears :
  3. html appears :
  4.  
  5.  
please help to solve my problem
Thanks and Regards
Sang
Mar 28 '07 #44
r035198x
13,262 8TB
Hello Sir

Another help to do the above program in single method.
In the above program the count is seperate function and it is call on the main.
but i want to all this on main there is no other function call.

I will try this one but my output is 0 please help to do this

Expand|Select|Wrap|Line Numbers
  1. public class strcount
  2.  {
  3.     public static void main(String arg[]) {
  4.     String resume = "java,html,jsp,c,java,dhtml,unix,html";
  5.      String word = "java,jsp,html";
  6.     String temp[] = word.split(",");
  7.         for(int i = 0; i < temp.length;i++) {
  8.          System.out.println(temp[i]+" appears : ");
  9.         }
  10.         int count = 0;
  11.     int wordLength = word.length();
  12.     for(int j = 0; j < resume.length() - wordLength; j++) {
  13.      if(word.equals(resume.substring(j, j + wordLength))) {
  14.    count++;
  15.    //System.out.print((temp[i]),count);
  16.      }
  17.     }
  18.     System.out.println(count);
  19.     //return count;
  20.     }
  21.  }
  22.  
output is like this
Expand|Select|Wrap|Line Numbers
  1. java appears :
  2. jsp appears :
  3. html appears :
  4.  
  5.  
please help to solve my problem
Thanks and Regards
Sang



Do not change the structure of your main method, just change the part that called the function and replace that part with the function itself with slight modifications. Why don't you want to call the function?
Mar 28 '07 #45
sang
83
Do not change the structure of your main method, just change the part that called the function and replace that part with the function itself with slight modifications. Why don't you want to call the function?
I do this program in jsp. I don't know how to call the function in jsp because the inputs are taken from the database. i think the main method is easly implemented in jsp. I am also do this in jsp but it print the keywords only the count values is 0. so that i ask how can i do this without function call.

Please help to do this

Thanks and Regards
Sang
Mar 28 '07 #46
r035198x
13,262 8TB
I do this program in jsp. I don't know how to call the function in jsp because the inputs are taken from the database. i think the main method is easly implemented in jsp. I am also do this in jsp but it print the keywords only the count values is 0. so that i ask how can i do this without function call.

Please help to do this

Thanks and Regards
Sang

Expand|Select|Wrap|Line Numbers
  1. public class strcount {
  2.     public static void main(String arg[]) {
  3.         String sentence = "java,jsp,c,dhtml,unix";
  4.         String word = "java,html";
  5.         String temp[] = word.split(",");
  6.         int count = 0;
  7.         for(int i = 0; i < temp.length;i++) {
  8.             System.out.print(temp[i]+" appears : ");
  9.             count = 0;
  10.             int wordLength = temp[i].length();
  11.             for(int j = 0; j < sentence.length() - wordLength; j++) {
  12.                if(temp[i].equals(sentence.substring(j, j + wordLength))) {
  13.                    count++;
  14.                }
  15.             }
  16.               System.out.print(count + " times");
  17.             System.out.println();
  18.         }
  19.  
  20.     }
  21.  
  22.  
  23.  }
Mar 28 '07 #47
sang
83
Expand|Select|Wrap|Line Numbers
  1. public class strcount {
  2.     public static void main(String arg[]) {
  3.         String sentence = "java,jsp,c,dhtml,unix";
  4.         String word = "java,html";
  5.         String temp[] = word.split(",");
  6.         int count = 0;
  7.         for(int i = 0; i < temp.length;i++) {
  8.             System.out.print(temp[i]+" appears : ");
  9.             count = 0;
  10.             int wordLength = temp[i].length();
  11.             for(int j = 0; j < sentence.length() - wordLength; j++) {
  12.                if(temp[i].equals(sentence.substring(j, j + wordLength))) {
  13.                    count++;
  14.                }
  15.             }
  16.               System.out.print(count + " times");
  17.             System.out.println();
  18.         }
  19.  
  20.     }
  21.  
  22.  
  23.  }
Hello Sir,
I want to use above code in jsp page to print the keywords and count. But the count values is not correct .

please help to do and also how can i place this code in jsp.
my code.
Expand|Select|Wrap|Line Numbers
  1. <table  border="0" cellspacing="4">
  2.   <tr>
  3.  
  4.     <td width="241" align="right" valign="middle" bgcolor="#0F6484"><div align="center" class="joblisting">Keyword</div></td>
  5.     <td width="122" valign="middle" bgcolor="#0F6484"><div align="center" class="joblisting">NoOfCount&nbsp;&nbsp;</div></td>
  6.   </tr>
  7.   <%
  8.     String UserId=request.getParameter("UserId");
  9.     String JobRefNo=request.getParameter("JobRefNo");
  10.     String Resume=request.getParameter("Resume");
  11.  
  12.     String sql1 = "select Keywords from JOB_ORDER a, JOB_APPLICATION b, CAN_RESUME c where a.JobRefNo=b.JobRefNo and a.JobRefNo="+ JobRefNo+" and c.UserId="+UserId;
  13.  
  14.  
  15.     Statement stm1 = dbConnection.createStatement();
  16.         ResultSet rs1 = null;
  17.         rs1 = stm1.executeQuery(sql1);
  18.         rs1.next();
  19.         String Keywords=rs1.getString(1);
  20.         String temp[] = Keywords.split(",");
  21.         for(int i = 0; i < temp.length;i++) {
  22.  
  23.  
  24. %>
  25.   <tr>
  26.  
  27.     <td align="left" valign="middle" class="altrow2"><%= temp[i] %></td>
  28.     <% 
  29.  
  30.     String sql2 ="select Resume from CAN_RESUME a,JOB_APPLICATION b,JOB_ORDER c where b.JobRefNo=c.JobRefNo and a.UserId=b.UserId and a.UserId="+UserId;
  31.     Statement stm2 = dbConnection.createStatement();
  32.         ResultSet rs2 = null;
  33.         rs2 = stm2.executeQuery(sql2);
  34.         rs2.next();
  35.         String Resume1=rs2.getString(1);
  36.         %>
  37.  
  38.     <%!int count = 0;
  39.     int j;
  40.      %>
  41.  
  42.     <% int KeywordsLength = temp[i].length();
  43.             for( j = 0; j < Resume1.length() - KeywordsLength; j++) {
  44.  
  45.        if(temp[i].equals(Resume1.substring(j, j + KeywordsLength))) {
  46.                    count++; 
  47.     %>           
  48.  
  49.     <%  } %>
  50.     <%    } %>
  51.  
  52.     <td align="center" valign="middle" class="altrow2"><% out.print(count); %></td>
  53.   </tr>
  54.   <% } %>
  55.   <tr>
  56.     <td colspan="3" align="center"><img src="/epc/img/close.gif"  width="53" height="19"   onClick="javascript: window.close()"/> </td>
  57.  
Please help to correct the count values
Thnaks and Regards
Sang
Mar 30 '07 #48
r035198x
13,262 8TB
Hello Sir,
I want to use above code in jsp page to print the keywords and count. But the count values is not correct .

please help to do and also how can i place this code in jsp.
my code.
Expand|Select|Wrap|Line Numbers
  1. <table border="0" cellspacing="4">
  2. <tr>
  3.  
  4. <td width="241" align="right" valign="middle" bgcolor="#0F6484"><div align="center" class="joblisting">Keyword</div></td>
  5. <td width="122" valign="middle" bgcolor="#0F6484"><div align="center" class="joblisting">NoOfCount&nbsp;&nbsp;</div></td>
  6. </tr>
  7. <%
  8.     String UserId=request.getParameter("UserId");
  9.     String JobRefNo=request.getParameter("JobRefNo");
  10.     String Resume=request.getParameter("Resume");
  11.  
  12.     String sql1 = "select Keywords from JOB_ORDER a, JOB_APPLICATION b, CAN_RESUME c where a.JobRefNo=b.JobRefNo and a.JobRefNo="+ JobRefNo+" and c.UserId="+UserId;
  13.  
  14.  
  15.     Statement stm1 = dbConnection.createStatement();
  16.         ResultSet rs1 = null;
  17.         rs1 = stm1.executeQuery(sql1);
  18.         rs1.next();
  19.         String Keywords=rs1.getString(1);
  20.         String temp[] = Keywords.split(",");
  21.         for(int i = 0; i < temp.length;i++) {
  22.  
  23.  
  24. %>
  25. <tr>
  26.  
  27. <td align="left" valign="middle" class="altrow2"><%= temp[i] %></td>
  28.     <% 
  29.  
  30.     String sql2 ="select Resume from CAN_RESUME a,JOB_APPLICATION b,JOB_ORDER c where b.JobRefNo=c.JobRefNo and a.UserId=b.UserId and a.UserId="+UserId;
  31.     Statement stm2 = dbConnection.createStatement();
  32.         ResultSet rs2 = null;
  33.         rs2 = stm2.executeQuery(sql2);
  34.         rs2.next();
  35.         String Resume1=rs2.getString(1);
  36.         %>
  37.  
  38.     <%!int count = 0;
  39.     int j;
  40.      %>
  41.  
  42.     <% int KeywordsLength = temp[i].length();
  43.             for( j = 0; j < Resume1.length() - KeywordsLength; j++) {
  44.  
  45.      if(temp[i].equals(Resume1.substring(j, j + KeywordsLength))) {
  46.                  count++; 
  47.     %>         
  48.  
  49.     <% } %>
  50.     <%    } %>
  51.  
  52. <td align="center" valign="middle" class="altrow2"><% out.print(count); %></td>
  53. </tr>
  54. <% } %>
  55. <tr>
  56. <td colspan="3" align="center"><img src="/epc/img/close.gif" width="53" height="19" onClick="javascript: window.close()"/> </td>
  57.  
Please help to correct the count values
Thnaks and Regards
Sang
What answers are you getting and what are you expecting?
Mar 30 '07 #49
sang
83
What answers are you getting and what are you expecting?
The count value is incorrect. That is the sql1 gets the keyword form the dataabase and split it.
The sql2 gets the resume from database and check the resume with the keyword.
I want to count the noof keywords appears in the resume.
in normal java program it works well but in the jsp i got incorrect count values.
The count values are changed after refeshing (every time) of the page.

This is most urget so please help me as soon as possible

Please hel pto correct it
Thanyou,
Sang
Mar 30 '07 #50

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: cassandra.flowers | last post by:
Hi, I have another string handling question for the group, since you have all been so helpful in the past. Thank you. Basically, I want to do something really simple: Search a main...
10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
17
by: Olivier Bellemare | last post by:
I've tried to make a function that returns the middle of a string. For example: strmid("this is a text",6,4); would return "is a". Here is my code: char *strmid(char *texte, int depart,...
8
by: Jami Bradley | last post by:
Hi, I'm looking for an efficient way to do this, because I know it will be heavily used :-) I have a fixed width string and I need to substitute a substring of characters with new values. I...
29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
35
by: Cor | last post by:
Hallo, I have promised Jay B yesterday to do some tests. The subject was a string evaluation that Jon had send in. Jay B was in doubt what was better because there was a discussion in the C#...
7
by: Matteo Rattotti | last post by:
Hi all, i've noticed a strange beaviour of string.count: in my mind this code must work in this way: str = "a_a_a_a_" howmuch = str.count("_a_") print howmuch -> 3
5
by: ashurack | last post by:
I found a stored procedure online a while back and want to inplement it. The only problem is that it doesn't check to see if the number generated is currently in use in the DB. I know it's really...
4
by: sandvet03 | last post by:
I am trying to expand on a earlier program for counting subs and now i am trying to replace substrings within a given string. For example if the main string was "The cat in the hat" i am trying to...
3
by: moizpalitanawala | last post by:
Hello I want to do reverse each word of the String example if input String is "Hello World" then the output should be "olleH dlroW" i Have tried this far class g { static String s="Hello...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.