I need to read the lines beggining with *2* so I done:
s = new Scanner(new BufferedReader(new FileReader("example.dat")));
while (s.hasNext()) {
String str1 = s.nextLine ();
if(str1.startsWith("*2*")){
System.out.print(str1);
}
}
So this will read the whole line I'm fine with that, Now my issue is I need to extract the 2nd line beggining with numbers the 4th with numbers the 5th with success and the 7th(DPSRN). I was thinking about using a String dilemeter with | how to extract them once i've used the dilemeter.
consider this statement from a jsp file(there are many more statements like this in jsp file..) Statement -
<h:dataGrid something styleclass="styleclass1" something1 onClick="event" something2 <% this is a scriplet tag %> something3 style="style1">
<h:output text>hello i am text</h:output text> </h:dataGrid>
What I want is to extract(and store it somewhere) the part from "<" to ">" where:
< - is the one in "<h:dataGrid" > - is the one in "style1>" and not the('>') one that appears in the end of "</h:dataGrid>" or "<h:output text>" or "</h:output text>"
Problem is the text b/w && is in multi-line...&& there are scriplet tags in between them.. so i don't know how to extract this particular string.. i tried using using some regular expressions but couldn't find the exact one..
(this was just an example && instead of this "" tag it can be anything like again in this line :
<h:output text>hello i am text</h:output text>
I want to extract the string from "<" till ">" where :
< - is the one in starting of "<h:output text>" > - is the one in ending of "<h:output text>" and not the one in "</h:output text>"
However the difference b/w this example and the above mentioned one is that this one is not multi-line and doesn't contains any scriptlet tags)....
i.e. the generic alternative, I get this error message:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -366 at java.lang.String.substring(Unknown Source) at main.HTMLGrabber.main(HTMLGrabber.java:45)
Is there a better and simple way to extract a substring?
I am trying to do is extract numbers that are in word format in a long String, i.e. a song, and return each of their numerical values, in order to add them all up. So I'd like to calculate the sum of all of the numbers in the text. This has to work for any piece of text and for all numbers up to a trillion.
So I broke the string down into tokens and stored them in a String []. And I divided up the possible numbers in word format into:
I believe that these are the only words that it will need to recognize. I began reading the tokenized string from right to left and then when I came across a unit, special or tens as the first number I hit, I would then set it's numerical value and check if the word before was also a number and whether to add or multiply etc. i.e. First number hit is a two, if the number before is sixty, then I would just add it to sixty and check the word before that and so on.
However, when implementing it, it seems like an extremely long way around it. How I could implement this in a swifter manner? An example of it working would be:
"Nine Million rockets turned Three times and met Twenty Two Aliens", it would extract, Twenty Two as 2, then 20 = 22, then extract Three as 3, and then Nine Million as 1,000,000 x 9 = 9,000,000
Add the following method to the BankAccount class: public String toString()Your method should return a string that contains the account's name and balance separated by a comma and space. For example, if an account object named benben has the name "Benson" and a balance of 17.25, the call of benben.toString() should return:
Benson, $17.25
There are some special cases you should handle. If the balance is negative, put the - sign before the dollar sign. Also, always display the cents as a two-digit number. For example, if the same object had a balance of -17.5, your method should return:
Benson, -$17.50
Here is my code:
public String toString() { String result = name + ", "; if (balance < 0) { result += "-"; } return result += "$" + Math.abs(balance); }
My code only works in case there are full two numbers for the cents part, not for the case when there's only one number. So I wonder how I can add an extra zero when needed.I can get only the decimal part and add a zero if it's less than 10, but I don't know how I can extract just the decimal part from the number. (The balance is just a double and it doesn't have any separate field for dollars and cents).
I am working on a card game and for lack of better terms, have royally screwed up my files. I do still have an executable jar that I would like to go back to if possible and try to redo what I messed up. What I was able to do was to use WinRAR and get ?encrypted? class files. Something that is obviously not editable. How can I go about converting these back to editable java files, if possible?
for my assignment I am to only add the sort and total inventory methods in the inventory class. And not create an array in the inventory class at all. My inventory class should contain all the variables needed to use with the two new methods: sort and calculate total inventory.By not creating any array in the inventory class and not touching the variables at all.For the inventoryTest class, I only need to declare an array of the inventory class by making an instance of the inventory.
public class inventory {
private int prodNumber; // product number private String prodName; // product name private int unitsTotal; // total units in stock private double unitPrice; // price per unit private double totalInventory; // amount of total inventory
I have a GUI that I've been working on for a while now. What I am trying to figure out, is a way to have the user push a button, and when they do have the GUI extend out to the right with another table to use for Filter Data. Once They are done, I want them to push that button again, and the panel with the query data retracts and is hidden again, all without changing the size of the current GUI in question. I've tried a bunch of different things with setting preferred and Minimal values to my GUI, and I've played around with different Layouts (Border Layout.East, etc), but I can't seem to find a good working solution.
Ideally it would be slick if I could make my panel SLIDE out and SLIDE back in, which would look really cool, but I'd settle for something that just worked.
I currently have a program written that outputs a canvas object and adds a picture of 5 taxis to it.I have now added a jtextfield so that a user can add an interger. Ideally if the user was to enter the number 8, there would be 8 taxis added to the canvas.I am having trouble with the final part i mentioned. how to delete the old canvas and output a new one with the amount that the user wrote in the jtextfield.
I have these sample strings in a text file : goldfish, fish, dish, filter and i need to extract them out with letters : "is" and need to print them out in another text file. Currently I am able to read the contents of the file but I am not able to print the same it in the new file.
public class Demo { public static void main(String[] args) { String filename = "a.txt"; try {
I have a page which lists items using a ui:repeat. The repeat is surrounded by my h:form tag.
Now I have made it so that when click an item, then I load some item details - render them in their own xhtml file and inject the result into the dom tree.
This is causing some problems.
* My injected content has commandButtons and commandLinks which do not work because I don't have a form in my injected page - since this would cause nested forms :-( * tried to replace commandButtons and commandLinks and instead create unique url's that I can call to get my work done - but how to I then re-render a panelGroup on then page? tried using jsf.ajax.request but I'm not able to get part of the page (a shoppingcart) to update
Basic outline
<h:form> <table> <ui:repeat ...> <tr><td onclick="...">Click here to load item details</td></tr><tr><td id="itemDetailPlaceholder"></td></tr> </ui:repeat> </table> </h:form>
I've been working quite a bit with a login system the past couple of months and I now have a version that I would like to try "for real" by extracting it as a runnable .jar or .exe file. I've looked at a couple of guides that told me how to do this properly, but even after following every step precisely it didn't work.
One of the guides I tried: 3 Ways to Create an Executable File from Eclipse - wikiHow
Double clicking the file or selecting it and pressing enter does nothing, the computer loads for a second and then nothing happens. I don't receive any visible errors when extracting the program, either.
However, when running the file from the command prompt I do receive an odd error: Microsoft Windows [Version 6.2.9200] (c) 2012 Microsoft Corporation. All rights reserved.
C:UsersUserName>java -jar Login.jar Exception in thread "main" java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(Unknown Source) at LoginSystem.Data.updateData(Data.java:347) at LoginSystem.Data.<init>(Data.java:309) at LoginSystem.MainFrame.<init>(MainFrame.java:42) at LoginSystem.MainFrame.main(MainFrame.java:457)
C:UsersUserName>
I must say I don't quite understand the error, it seems to be unable to load an image which is odd considering the program works fine without any errors at all in Eclipse.
I have to implement a system where I have to do almost same processing on a jsp page. The slight differences on the present page is based on whether the current page came from page 1 or page 2. So how can I do this?
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.
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) {
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));}}
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
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...
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.
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.