Manipulating A String

Jul 26, 2014

I have strings in forms like s="(S (NP (DT This)) (VP (VBZ is) (NP (DT an) (JJ easy) (NN sentence))))"Programatically, I need to have words which end with ')' to be in an extra pair of brackets.. such that s = "(S (NP (DT (This))) (VP (VBZ (is)) (NP (DT (an)) (JJ (easy)) (NN (sentence)))))

Note that , words like "this" and "is" are now enclosed in brackets.I tried to create a program which would search for an alphabet followed by ')' and would put it in bracket... but then arrays can't have insertions in between.

View Replies


ADVERTISEMENT

String Manipulation For Program Manipulating Name Of City

Jan 23, 2015

I have to write a program that asks the user to enter the name of their favorite city and use string variable to store the input. The program should display the following:

-The number of characters in the city name
-The name of the city in all uppercase letters
-The name of the city in all lowercase letters
-The first character in the name of the city

However, I can't seem to get past the following errors;

Programming Challenge #12.java:37: error: variable cityFirstChar is already defined in method main(String[])
char cityFirstChar = city.charAt(0);
^
8 errors[CODE
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
[/CODE]

My code is as follows:

import java.util.Scanner;
 
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
 
[code]....

View Replies View Related

Manipulating Data From Buffered Reader

Nov 3, 2014

I've got a .csv file with some text and numeric data. I've used BufferedReader to successfully print the data to the console. Now I need to perform mathematical operations on the numerical data. How do I access the data from the BufferedReader in my calculation methods?

This is what my BufferedReader looks like:

ReadCVS obj=new ReadCVS();
obj.run();
}
public void run(){
String csvFile = "myDataSet.csv";
BufferedReader buffread=null;
String row="";

[Code] .....

What I would like to be able to do is create some loops to calculate totals for some of the elements, but I'm not sure how to access the data from other methods (and potentially classes?).

View Replies View Related

Manipulating Strings In A File Scanner

Feb 25, 2014

I was given a text file that has list of names phone numbers, calls in and out etc... Like this

Adams#Marilyn#8233331109#0#0#01012014#C
Anderson#John#5025559980#20#15#12152013#M
Baker-Brown#Angelica#9021329944#0#3#02112014#C

The # are delimiters between data items and each line has the call status as the last item. I need to know how I can display each persons information on the screen in a format such as:

Name Phone Calls Out Calls In Last Call

Marilyn Adams (823) 333-1109 0 0 01-01-2104
John Anderson (502) 555-9980 20 15 12-15-2013
Angelica Baker-Brown (859) 254-1109 11 5 02-11-2014

I have to use substring method to extract the phone number and add parentheses/dashes ect I also must have a while statement and a delimiter...

So Far my code looks like this Also I am in a beginners Java coding class....

import java.util.Scanner;
import java.io.*;
 public class phonedata2_1 {
public static void main (String[] args) throws IOException {
  String Phonefile, FirstName, LastName;
Scanner PhoneScan, fileScan;
 
[Code] ....

View Replies View Related

Swing/AWT/SWT :: Double Drawing Pixels When Manipulating DataBuffer Of BufferedImage

Feb 9, 2014

I've been working my way through a tutorial to build a simple 2D tile-based engine that also allows the code to manipulate the colour of pixels on the screen based on a monochrome map read from a file. I've got the code right line for line, but I seem to have a bug when it comes to draw to the screen! At regular intervals, despite what is held in the pixel array of ints (which I have confirmed to be correct when debugging), I get the same row of pixels being draw twice in a row. I figured there was some loop issue somewhere, but after attempting to debug this for some time, I haven't come up with the answer.

Original tilesheet:As rendered:

Game.java:
package igg.engine.game;
import igg.engine.game.gfx.Screen;
import igg.engine.game.gfx.SpriteSheet;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;

[Code] ....

View Replies View Related

JavaFX 2.0 :: Manipulating Several Windows (Window Inside Window)

Apr 6, 2015

I am new to javafx I start using it instead of swing i used the scene builder for my forms the problem i faced i don't know how to have main screen with menu bar at top and depending the select from the menu it will open other windows and those window must be inside my window just like for example netbeans.

I don't need to open new window in separate i need all windows inside my main window and controlling over them minimize maximize perhaps.

View Replies View Related

Method Creation - Take A String With Duplicate Letters And Return Same String Without Duplicates

Nov 7, 2014

How can I write a method that takes a string with duplicates letters and returns the same string which does not contain duplicates. For example, if you pass it radar, it will return rad. Also i would like to know how can I Write a method that takes as parameters the secret word and the good guesses and returns a string that is the secretword but has dashes in the places where the player has not yet guessed that letter. For example, if the secret word is radar and the player has already guessed the good guesses letters r and d, the method will return r-d-r.

View Replies View Related

String Split Method To Tokenize String Of Characters Inputted?

Sep 27, 2014

I am currently trying to make a calculator in Java. I want to use the String split method to tokenize the string of characters inputted. I thought I was using the String split method wrongly, because I had surrounded the characters I wanted to delimit with square brackets. However, when I removed the square brackets, the code threw an exception when I pressed the equal button. The exception was a PatternSyntaxException exception. Am I using the String split method wrongly? And why is the exception thrown? Here is my code:

import javax.swing.*;//import the packages needed for gui
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import java.util.List;
import static java.lang.Math.*;
public class CalculatorCopy {
public static void main(String[] args) {

[Code] .....

View Replies View Related

Class Method Which Take String And Returns A String In Reversed Version

Dec 16, 2014

i am trying to write a class method which will take in a string and returns a string which is the reversed version of that string. it compiles fine but when i try to run it it states Main method not found in class StringReverse,please define the main method as public static void main(String[]args). I am new to java and cannot figure out

import javax.swing.JOptionPane;
public class StringReverse {
public String reverseString(String str){
JOptionPane.showInputDialog(null,"Please enter word");
char c = str.charAt(str.length()-1);
if(str.length() == 1) return Character.toString(c);
return c + reverseString(str.substring(0,str.length()-1));}}

View Replies View Related

Take Replacement String Entered By User And Print Out New String

May 22, 2014

I'm having trouble with the last few lines of the code. It's supposed to take a replacement string entered by the user and print out the new string. For some reason it's now allowing me to enter a replacement string

import java.util.Scanner;
public class Project02 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a long string: ");
String lString = keyboard.nextLine();

[Code] ....

Output:

Enter a long string: the quick brown fox jumped over the lazy dog
Enter a substring: jumped
Length of your string: 44
Length of your substring: 6
Starting position of your substring in string: 20
String before your substring: the quick brown fox
String after your substring: over the lazy dog
Enter a position between 0 and 43: 18
The character at position 18 is x

Enter a replacement string: Your new string is: the quick brown fox over the lazy dog <------ isn't taking user input

View Replies View Related

Swing/AWT/SWT :: Compare Inputted String With Key String

Aug 28, 2014

I have a method for a button so when a user inputs something it then will get the string value and check it against the string value within the properties file to see if it exists.

The properties file is called GitCommands.properties that contains -- > key = value <-- in it

I realised I have not used it correctly hence why I keep getting errors - I am lost on how to use it, I think perhaps that may be the issue here? I need to reference the file but I am doing it wrong? When I do use that piece of code I get null pointer exception too...

textFieldSearch.getText().equals(GitCommands.keys());

This is my button:

JButton btnSearch = new JButton("Search");
btnSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
FindSelectedKey();

[code] .....

I understand I am missing my piece of code where it states "//determine whether the string is equal to the property file key string" I understand the logic fine but not actually coding it.

View Replies View Related

Split String Based On String Length?

Jan 23, 2010

I am trying to split a string based on length(example length 5) of the string. But I am having a issues with this substring(start, end) method. I get all substring which are of length 5. But if the last substring is less than 5 then I am not getting that last substring. But I need the last substring even if it is less than 5.

String s = "fjdjfdfjgffgjhfjghfjkhjhjh";
String spLine;
for(int i=0; i<s.length(); i=i+5){
spLine = s.substring(i, (5+i));
}
>

View Replies View Related

Accepting String And String Array In Just ONE Method?

Mar 18, 2014

Code a Java method that accepts a String array and a String. The method should return true if the string can be found as an element of the array and false otherwise. Test your method by calling it from the main method which supplies its two parameters (no user input required). Use an array initialiser list to initialise the array you pass. Test thoroughly.

public class test {
public static void main(String[] args) {
Printhelloworld();
String[] verbs = {"go", "do", "some", "homework"};
printArrays(verbs);

[Code] .....

View Replies View Related

How To Use Previous String Compare To Current String

Mar 2, 2014

I'm having trouble to compare two string from my LinkedList. I took me 2 days now trying figure out how to compare the current string to previous string in the linkedlist. Here is my code.

public int compareTo(LinkedListNode n){
//Compare two string
String myHead = data.toLowerCase();
String comparableHead = data.toLowerCase();
 
return (myHead.compareTo(comparableHead));
}

View Replies View Related

How To Compare String To Each Element Of String Array

Mar 28, 2014

How do I compare a String to each element of a string array?

For example:

int headscount = 0;
if (coins[i].equals("heads")){
headscount++;
System.out.println("b" + headscount);
}

This doesn't give me the right value because the IDE says that equals() is an incompatible type. I also tried changing the "heads" to an variable, but the results remains the same.

I would prefer using an Array!

View Replies View Related

String Split Method To String Array

Sep 21, 2014

So I'm creating a class which when given three inputs uses them as sides of a triangle and tells ther user what type of triangle it is, or if the input is invalid, tells them why it is invalid. I'm readin the input as a string and then trying to split it into a string array, from there checking to see if it has 3 elements.. in which the data is good at that point, and then converting them to ints and checking to see if they're negative ansd finally checking to see if they can work as sides of a triangle ie a+b >c, a+c >b , b+c >a.

I'm trying to split it into an array of strings but am getting an error, and can't seem to figure out why as this should be working from what I've read of the string.split method online.

import java.util.*;
public class TriangleTest{
private int sideA;
private int sideB;
private int sideC;
public static void main(String[] args){
TriangleTest triangle = new TriangleTest("3 4 5");

[Code] ....

The output reads [Ljava.lang.String;@15db9742

View Replies View Related

Encode URL String - It Will Accept Only 1 String Argument

Mar 30, 2015

I've a problem in encoding a URL string.

I know to encode a string we use,

URLEncoder.encode(stringname,"UTF-8");

But when I use this I'm getting an error telling that the encode method will accept only 1 String argument.

View Replies View Related

How To Convert Numeric String To Formatted String

Sep 11, 2014

I have a string value returned from a background tool that will range from 0 to possibly terabytes as a full number.  I want to format that number to use commas and to reduce the character count using an appropriate size modifier (KiB, MiB, GiB, etc).  I've tried converting the string number to a Double value using Double.parseDouble() and then performing the math based on the size of the value with this code:
 
Double dblConversionSize;
String stCinvertedSize;
dblConversionSize = Double.parseDouble(theValue);
if (dblConversionSize > (1024 * 1024 * 1024))
     stConvertedSize = String.format("%,.000d", dblConversionSize / 1024 / 1024 / 1024) + " TiB";
...
 
I've also tried using
 
     String.valueOf(dblConversionSize / 1024 / 1024 / 1024) + " TiB";
 
However, the formatting is failing and I'm either getting a format exception or the result is displayed as a number with no decimal component.

View Replies View Related

Cannot Convert From String To Boolean And Int To String

Apr 6, 2014

I have errors in the "if" and both "else if" ... The compiler says "cannot convert from String to boolean and int to String ...

instructions:

1. Add two private instance variables, String courseName and char grade to this class.

2. Add accessor and mutator methods for these instance variables.

3. Add a method register which receives an integer data type and returns String data type according to the argument passed to it ("Math" for 1, "English" for 2, "No course" for any other input)

What I have so far:

package assignment9;
 public class BannerUser
{
private int userId;
public int getUserId()
{
return this.userId;
}
public void setUserId(int userId)

[Code] ......

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

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

Difference Between String And String?

Apr 27, 2015

What is the difference between string and String (note the case)

View Replies View Related

Using Int To Get A Value From A String?

Oct 10, 2014

Anyways, variable names I have gotten from the code I've gotten from Minecraft using MinecraftCoderPack & Eclipse.

So... I have a string that I am wanting to get a number from.

Example:

public static final String[] exampleLetters = new String[] {"a", "b", "c", "d", "e", "f", "g"};

And, using a public Int (with no variables in the title), I am looking to take numbers for each string letter, to be able to output the value to other code.

Example:
public int letterConversion()
a = 0, b = 1, and so on to g = 6

How would I be able to get the numerical values of each letters using a public Int without any variables in the title?

Actual Code I have right now. Again, please ignore variable names, it's what I got use to while learning.

/** The list of the types of step blocks. */
public static final String[] slabType = new String[] {"stone", "sand", "cobble", "brick", "smoothStoneBrick", "netherBrick", "quartz"};
}
/**This checks slabType for the material and registers a number to each type for other codes to use.*/
public int textureType()

[Code] ....

For what I have now, in the Int...

for ( int var2 = 0 ; var2 < slabType.length ; var2++ )

Is controlling the output. No mater what the 0 is the output...

View Replies View Related

JSP :: How To Get String From Servlet

Nov 5, 2014

I'm trying to work out how to get a string from a servlet in to the JSP, The code I thought would work was as follows.

request.getSession().setAttribute("test", "this is a test");
request.getRequestDispatcher("C:myjsp.jsp").forward(request, response);

<%
String s1 = (String) session.getAttribute("test");
%>
<%= s1 %>

This is returning null ...

I have tried a few examples and followed a few tutorials but I keep getting null or nullpointexceptions.

View Replies View Related

Re-prompting For A String?

Mar 28, 2014

how to have a user input information again if their initial one was incorrect? For example, in this it will have the user go back to select an invoice number within range, but how do you do so if they enter words? I've tried next() and nextLine() but it hasn't worked.

Scanner input = new Scanner(System.in);
System.out.println("What is the invoice number for your purchase?");
invoice = input.nextInt();
  System.out.println("What is the sale amount of your purchase?");
amount = input.nextDouble(); 
while (invoice < 1000 || invoice > 8000) {
System.out.println("You have entered an invalid invoice number.");
System.out.println("Please select a number between 1000 and 8000.");
invoice = input.nextInt();//having trouble knowing how to input this if it were a string.
}

View Replies View Related

How To Parse A String

Jul 10, 2014

I'm learning about inheritance and on this problem I first have to create a class where I get/set methods and get user input for the data fields.

I suppose I should know it at this point but I don't know how to get the users name when they input it. I copied the whole code but the issue is at line 51.

import javax.swing.JOptionPane;
public class Order {
private String customerName;
private int customerNumber;
private int quantityOrdered;
private double unitPrice;
private double totalPrice;

[Code] .....

View Replies View Related







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