Delimiter Function And Number Of Words In String

Apr 20, 2014

Working on my java skills. The is Delimiter function is suppose to return true if there is a delimiter in the string and false otherwise. The main is suppose to call this function and count the number of words in the string:

Here is what I came up with:

import java.util.*;
 public class NumberOfWordsInString {
public static void main (String[] args){
Scanner in= new Scanner (System.in);
String s;

[Code] ....

Somehow my method isn't being successfully called by my main and the following error msg was received:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

length cannot be resolved or is not a field

The method isDelimiter(char) in the type NumberOfWordsInString is not applicable for the arguments (char[])

at javaimprovements.NumberOfWordsInString.main(Number OfWordsInString.java:10)

line 10:
char ch [] = new char [s.length];

and the main doesn't call the isDelimiter function

View Replies


ADVERTISEMENT

Replace Value Of Delimiter In String

Jan 8, 2014

How can I change the value of

String str = "1234|U||45|||"
into
String str = "1234|U| |45| | |"

View Replies View Related

How To Split String When Delimiter Also Is In The String

Mar 25, 2015

I have the the string value similar to the one   which i have to split based on the delimited ","
String SampleString=" 'ab,c', 'xyz', lm,n,o  "
 
I know I can easily call split function which will eventually split the above string. But in my case the delimiter ","  , is also a part of the string. If I call the function SampleString.split(',') I will get the output as listed below
 
ab
c
xyz
lm
n
o
but the expected  output is
abc
xyz
lmno

View Replies View Related

Counting Number Of Words From User Input

Jan 2, 2015

I tried the following code, OK:

Java Code:

String temp = "hi this sf hello is new what is this";
String[] cmd = temp.split("s");
int num = cmd.length;
System.out.println("number of words are: "+num); mh_sh_highlight_all('java');

However, when i get the input from user , i didnt get the expected result:

Java Code:

System.out.println("Enter the input string to count the words: ");
String[] cmd = new Scanner(System.in).next().trim().split("s");
int num = cmd.length;
System.out.println("number of words are: "+num); mh_sh_highlight_all('java');

Now Result for above code:

Enter the string to count the words:

hi this is new

words are: 1

View Replies View Related

Match Phone Number To 7 Letter Words

Jul 25, 2014

I got a phone number problem. I get a list of phone numbers and a word file containing words, how could I need to see if I could match the phone number to 7 letter words, then see if I can match the first 3 numbers to 3 letter words and then the last 4 numbers to 4 number words. I figured all that out so far. The last part of this assignment is to see if I could match a combination of words together to match the phone numbers.

Example:
531 3259
IGETMILK

View Replies View Related

Accept String And Number Of Repetitions As Parameters And Print String Given Number Of Times

Oct 3, 2014

I'm having a hard time with this problem, this is what I have, but I can not use two integers, I have to use one integer and a string...

This is the question:

Write a method called printStrings that accepts a String and a number of repetitions as parameters and prints that String the given number of times. For example, the call:

printStrings("abc", 5);

will print the following output: abcabcabcabcabc

This is what I attempted:

public class printStringsproject {
public static void printStrings(int abc, int number) {
for (int i = 1; i <= number; i++) {
System.out.print("abc");
}
}
public static void main(String[] args) {
printStrings(1, 5);
}
}

View Replies View Related

Using String Methods To Count Words?

Nov 3, 2014

Aeparated by blanks in a string. For simplicity, use strings without punctuation or other white space characters(tabs, newlines etc). Use a JTextArea to allow the user to enter the text and allow the text area to scroll if necessary. when the user clicks a button to count the words , the total number of words counted is displayed in a textbox that cannot be modified by the user.

now my problem is that i am not getting the counted number to display in the un-editable textbox. i also have the problem where the cusrsor is showing in the middle of the input screen instead of at the top.

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.*;
import java.util.*;
public class WordCounter extends JFrame implements ActionListener

[code]....

View Replies View Related

String Of Words - Getting First Letter From Each Word?

Mar 26, 2014

If I have a string of words and want to get a letter from each word (let's say the first), how do I code for anything past two?

For example, if I have North Atlantic Treaty Organization and I want to convert it to NATO I would do something like:

charAt(0) for N
charAt(x + 1) for A

But what do I do for anything past the second string? If I do charAt(x ++ 1) I get an error.

View Replies View Related

Fibonacci Number - Recursive Function

Jul 8, 2014

I wrote this tail recursive function that mirrors the iterative version, except that the loop in the iterative version is replaced by an if statement here and then a recursive call. Is this truly recursive? I have seen the fibo(n-1) + fibo(n - 2) version, but is this also an acceptable recursive solution? Why is it never solved this way?

public class FiboRecursive {
public static int fibo (int n) {
int sum = 0;
int n1 = 1;
int n2 = 1;
if (n == 1 || n == 2) {
sum = 1;

[Code] ...

View Replies View Related

Accept A String And Display All Palindrome Words

Jan 23, 2015

The program is to accept a string and display all the palindrome words(the words that are same even if they are reversed-------->mom,madam,malayalam etc.)in the string.

I need to solve this program urgently.

There are no syntax errors but after typing in the sentence,no output is displayed. This is my program....

import java.util.*;
class palindrome_test
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Enter a sentence");
String usersInput=in.nextLine();

[Code] .....

View Replies View Related

Taking String That Contain Sentence And Reversing The Words

Sep 5, 2014

I am not very comfortable with Strings in Java. The problem I am facing is, taking a string that contains a sentence and reversing the words. Example would be, "Hi I am Bob" and changing it to "Bob am I Hi". Then returning the String.

My initial thoughts were to change the string into a character array and then manually doing the work with loops and tedious comparison statements. I quickly realized that there must be a better way but I am not very familiar with strings in Java to know what a more sufficient way would be.

View Replies View Related

String Analyze - Take A Sentence And Check How Many Times Specific Words Come Up

Sep 8, 2014

Basically the requirements are to take a sentence (string of text) and check to see how many times specific words come up and then add to the counter depending on the word.

But I can not seem to get it to add the instances of the goodwords and badwords.

package Strings;
import java.io.*;
public class SentimentAnalyser {
private static String analyse(String text) {
int pw = 0;
int nw = 0;
String[] searchword = { "bad", "terrible", "good", "awesome" };

[Code] ....

View Replies View Related

How To Call The Function String

Mar 17, 2015

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class vowels{
public static void main(String arg [])
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a String : ");

[Code] .....

View Replies View Related

Program That Accept Words And Their Meanings Or Display List Of Words In Lexicographical Order

Apr 15, 2015

Write a menu driven program that either accepts words and their meanings, or displays the list of words in lexicographical order (i.e. as in a dictionary). When an entry is to be added to the dictionary you must first enter the word as one string, and then enter the meaning as separate string. Another requirement - from time to time words become obsolete. When this happens, such word must be removed from the dictionary.

Use the JOptionPane class to enter the information.

Use the concept of linked list to carryout this exercise. You will need at minimum the following classes:

- A WordMeaning class that hold the name of a word and its meaning.
- A WordMeaningNode class that creates the node of information and its link field.
- A WordList class that creates and maintain a linked list of words and their meanings.
- A Dictionary class that test your classes.

For the output, the program should produce two scrollable lists:

- The current list of words and their meanings.
- The list of the deleted words. You need not list the meanings, just the words.

So far, I have everything coded except for the remove method, and I am not sure how to code that. I coded the add method already, but now I don't know where to begin with the remove method in my WordList class. My classes are below.

WordMeaning Class:

public class WordMeaning {
String name;
String definition;
WordMeaning(String t, String d) {
name = t;
definition = d;

[Code] .....

View Replies View Related

String Pool And Function Call

Aug 23, 2014

String pool puzzles me again. I think a==b and a==c are both true...

public class StringPoolTest {
public static void main(String[] args) {
String a = "abc";
String b = f() + "c";
String c = g();

[Code] .....

View Replies View Related

Function That Will Add Contents Of String Array

Sep 18, 2014

Write a function that will add the contents of a String array.

1. This time the input array to your function will be an array of Strings.

2. Your function body will be similar except you'll have to convert each String to a double number.

public class SumVals2 {
String aryVals[];
double result;

[Code]....

View Replies View Related

Split String Function No Longer Works

Jun 23, 2014

I am encountering a problem while running this small piece of code.

public class TestSplit{
public static void main(String[] args){
String myWords[]="My.Home.Is.Being.Painted".split(".");
for(int i=0;i<myWords.length;i++)
System.out.println(myWords[i]+" ");
}
}

The problem is: it does not run at all. No error message is displayed. It just returns to the command prompt when i run it. Where am i wrong?

View Replies View Related

I/O Arrays - Count Number Of Repetitiveness In String For The Number

May 19, 2014

//read the file
//make the numbers 1 string line
//count the number of repetitiveness in the string for the numbers
//display four lowest ones

import java.io.*;
import java.util.*;
public class Lottery2

[Code] ....

when I run it the array gets sorted but how do i keep the data in other words

what it is supposed to do is grab numbers from a file, and give me the lowest 4 numbers back. I know the numbers using the array but how do i pull out the lowest 4 and keep the data true no matter what numbers or how many of them are in the file.

View Replies View Related

FILE Input Without Delimiter

Apr 28, 2014

This is my input from my text file: 1|John Jay Smith|1985-01-10|2010-05-10|2014-03-05|212-222-2233..So, I have to convert 1 to integer. Break John Smith into first name as John and Middle name as Jay Last name as Smith.If no middle name is given then first is John and Last is Smith . Read 1985-01-10 as a date value . 2010-05-10 as another date value which could be null. 2014-03-05 as another date value which could be null. and at last 212-222-2233 as phone number.

Scanner sc = new Scanner (inFile);
sc.nextLine();
while (sc.hasNext()){

String row= sc.nextLine();

I want to read this line of input and assign the value accordingly.

View Replies View Related

I/O / Streams :: Reading Up To The First Delimiter And Then Moving On To Next Line?

Mar 22, 2014

I have a text file that has contents as follows:

testing1,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0
test2,true,0,0.0,0,0.0,4.0,0.0,0.0,0.0,0.0

I am trying to read only the first item in each list using a comma as a delimiter using the following code.

public String[] pList() {
ArrayList<String> names = new ArrayList<String>();
String word;
try {
String path = P_FOLDER + P_FILE;

[Code]....

View Replies View Related

Delimiter - Type In 5 Strings From Java Console And Print Them All Out

Feb 13, 2015

I am testing some stuff here is my code:

public static void main(String[] args) {
String[] a = new String[5];
//String input = JOptionPane.showInputDialog(null, "enter input");
Scanner scanner = new Scanner(System.in);

[Code] ....

I am trying to type in 5 strings from java console and print them all out. I am using a "/" as a delimiter. My problem is that it does not print any output after I type strings separated by "/" like this: hello/gea/cae/eaf/aer and press enter. It works if I use JOptionPane but from the console its not working. I want to use the console instead of JOptionPane for this one.

View Replies View Related

Alphanumeric And Pipe Delimiter Regular Expression Validation

Sep 4, 2014

I have a header in file like below:
 
EMP_ID|EMP_NAME|DEPARTMENT|SALARY|ACTIVE1
 
passed to a string

String test = "EMP_ID|EMP_NAME|DEPARTMENT|SALARY|ACTIVE1";
 
I have to check if the header has only alphanumeric and pipedelimiter is allowed.

Other than these i need to raise an error.

View Replies View Related

JSF :: Call Function Inside Other Function

Jun 23, 2014

I would use the return value of a function how parameter of other function..In java is:

// the call produce "YES"
SecondClassController.funcSecondClass(FirstClassController.funcFirstClass());

In my web page I need to do something like this:

[...]
<h:outputText value="#{secondClassController.funcSecondClass(#{firstClassController.funcFirstClass()})}" />
[...]
obtain:
javax.servlet.ServletException JBWEB006007: Failed to parse the expression
@Named
@SessionScoped
public class FirstClassController implements Serializable{
[...]

[code]....

View Replies View Related

How To Check If At Least One Number In A String Is Different From 0

Nov 18, 2014

I'm trying to come up with a method that would validate each turn a player makes. For a turn to be valid, it has to only contain numbers from 0 to 3(inclusive) and at least one digit must not be 0. Here is what I`ve come up with so far. For example, with "303" as the number and "101" as the turn, the turn would be valid and my method should return true, but it does not.

public static boolean turnIsValid (String number, String turn ){
boolean rep=false;
int pos1=0;
char min='0';
char max='3';
while(number.length()==turn.length()&&pos1<turn.length()){

[Code] ....

View Replies View Related

Masking Of Number In A String?

Jan 14, 2014

My requirement is to

1- mask the number(whose length is between 10 to 12).

2- central digits are replaced by 'X' and 1st and last two digits remains unchanged

Input string: dsfjgjkdfgjdsfjg12345678901fdgkhfdklg55555hfdkhg
output string: dsfjgjkdfgjdsfjg12XXXXXXX1fdgkhfdklg55555hfdkhg

In the above example number 123456789012 is masked to 12XXXXXX01 but the number 55555 remains same as length of 55555 is 5 and we will only mask the number whose length is between 10 to 12 .

View Replies View Related

How To Return Value Certain As Number And Some As String

Nov 23, 2014

I've to return some value as a string and some as a int, how is this possible? Here's my code:

public class Card {
public void start(){
String [] suit = {"Spade","Club","Diamond","Heart"};
int [] number = {1,2,3,4,5,6,7,8,9,10,11,12,13};}
public String getColour(){
String [] suit = {"Spade","Club","Diamond","Heart"};

[Code] .....

So at the top, i've set it to return value as string because of the King Jack Queen and Ace, but i also have to return as numbers(int). And also i'm using a loop to read all the numbers, is there any other way?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved