-
May 9th, 2014, 04:05 AM
#1
Scanner Class
Dear All
Please help me out. This is just a simple porgram in BjueJ where the program accepts a sentence & a word. Returns the number of times the word exists in the sentence using the Scanner class. The code is given below
import java.util.* ;
public class ScannerClass1
{
public void main()
{
int c =0 ;
Scanner sc = new Scanner (System.in); // accept input from std input keyboard
System.out.print("Enter Sentence: ");
String s=sc.nextLine();
System.out.print("Enter Search Word: ");
String ss=sc.nextLine();
while(sc.hasNext())
{ String d=sc.next();
if (d.equals(ss))
{
c++;
}
}
System.out.println("Search word exists " + c +" times") ;
}
}
The program is accepting the inputs, but not processing further, getting into a continuous loop. Have to use crtl+shift+r to reset.
Last edited by amarjitamarNew1; May 9th, 2014 at 04:16 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|