Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have a file "file.txt" in Java. In the file I have the following values:
10 10
3 3 W
MMMMMRM
4 4 R
LRLRLML
I want to read each line and with each character I want to assign them to a variable which I will use for calculation.
Any idea with how I can proceed with?
Thanks
1) You can use a BufferedReader with the readLine() method to read each line.
2) Then you can use split() for each word or toCharArray() for each character.
3) Then assign said character to predefined variables.
It would be helpful if we could see what you've tried so far or if you could give more details on what you are trying to accomplish.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
For example, if I have a string (24/25), how would I go about being left with two double values of 24 and 25. My objective to to eventually, given a set of number of that form, divide each of them, and add to get the average. I'm fairly new to Java and I honestly am so confused as where to even begin. Thank you!
As Andreas said. First you need to take the substring between brackets. Use String.substr
Now split 24/25 to 24 and 25. You can use String.split
Then you can parse them with Double.parse
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
it is possible to assign that big number in java? i need to make a calculation of 39 digits value. could any help? Thanks
Problem:
Consider the following composite number:
340282367237851113557325445936183246849
Write a Java method to find two numbers whose product is the above number.
I guess you need to check out the BigInteger of the java API. That might be able to store your results of those much big numbers. Read the documentation,
http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to display the first folder name from the path.
/mnt/sdcard/Videos/lk.jpeg, I want to display mnt string. in java
/mnt/sdcard/Videos/lk.jpeg--> **mnt**
You can split on / and use [1] element from result array.
You can either use regular expressions or you can use String.split(). Note that the split() result should be checked for live usage (e.g. if it has at least two elements).
String desired = "/mnt/sdcard/foo".split("/")[1];
String str = "/mnt/sdcard/Videos/lk.jpeg";
System.out.println(str.split("/")[1]);
Try this out. This is a poor question. But maybe the asker can be a newbie.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
can someone give me a proper explanation why in java (or is this applicable to all programming language?) if the path is retrieved from the database, it is okay to use only 1 slash like '\192.168.173.220\folder\folder1\folder2' instead of '\\192.168.173.220\folder\folder1\folder2'.
When you write a String literal in Java source code, you need to escape backslash characters.
But in a String object ... which is what you get at runtime when you read a String from a database (or anywhere else) ... each character stands for itself.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I don't know a single bit about regex. I want to find certain occurences in my java project using eclipse. The words could be
SEQ_NUM
SEQNUM
SEQNUMBER
SEQ_NUMBER
searching strings based on word "seq" would generate lots of results. What regex should suffice my problem?
These four cases can be combined to the following regex:
SEQ_?NUM(BER)?
SEQ_?NUM(BER)?
SEQ - must exist
_? - '_' can appear 0 or 1 time
NUM - NUM must also exist
(BER)? - 'BER' can appear 0 or 1 time
This should work for you.
SEQ[_NUMBER]+