|
The users of this lib seem satisfied PDFToHTML[^]
Good Luck
|
|
|
|
|
Hello
i 'd like to know whether i can use .NET Framework inside Java or use .NET Framework classes and methodes in Java
Many Thanks
Thierry
|
|
|
|
|
Aside from J# I do not know of any interoperable software to do so. However, I use both in almost all the code I write. For example, If I want a feature that is not available in Java by default and is found in C# then I implement it using C# and make an executable and call it from Java. The calling varies depending on what I want some times I capture the output from the executable and process it in Java and other times I just let it do all the work.
|
|
|
|
|
|
You could convert the arrays to a list using Arrays.toList, then use Collections.indexOfSubList.
Or, if you want to do it yourself without converting the arrays to lists, take a look at the source for Collections.indexOfSublist to see how that does it, then implement your own version that operates directly in the arrays.
|
|
|
|
|
|
Snippet Example:
List<Integer> list = Arrays.asList(1,2,3,4,5);
System.out.println("List :"+list);
List<Integer> sublist = Arrays.asList(4,5);
System.out.println("SubList :"+sublist);
System.out.println("indexOfSubList: "+ Collections.indexOfSubList(list, sublist));
System.out.println("lastIndexOfSubList: " + Collections.lastIndexOfSubList(list, sublist));
if (Collections.indexOfSubList(list, sublist) != -1)
System.out.println(true);
else
System.out.println(false);
|
|
|
|
|
In your code you exit as soon as a mismatch is found rather then continuing to look in case the match occurs later.
Try this [untested]
static boolean hasSubsequence(int[] arr, int[] sub)
{
boolean matched = false;
for (int i=0;
i < arr.length-sub.length && !matched;
i++)
{
matched = true;
for (int j=0;
j <= sub.length && matched;
j++)
{
matched = (arr[i] == sub[j])
}
}
return matched;
}
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
|
try without the mistakes :
<pre> static boolean hasSubsequence(int[] arr, int[] sub) {
// no match for the outer loop
// this will exit when a match is found
boolean matched = false;
for (int i = 0; i <= arr.length - sub.length && !matched; i++) {
// start off matched for the inner loop
// this will exit when a mismatch is found
matched = true;
for (int j = 0; j < sub.length && matched; j++) {
matched = (arr[i+j] == sub[j]);
}
}
// at this point mayched is true if sub is inside arr
return matched;
}</pre>
Exercise for you is to work out WHY it was wrong....
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Hey, I was wondering if there are any jobs over the internet tht involve me taking part in a project that I don't get paid for, for example an unpaid position that I could simply be given a task and then log off the internet and complete the task. If you would like more information just ask...
- Todd.
|
|
|
|
|
|
I enjoy answering Java board questions
|
|
|
|
|
Member 4277480 wrote: I enjoy answering Java board questions
I've noticed that, you always offer very comprehensive answers. However, sometimes I think it does more good to get people to at least try and figure things out for themselves, so they may actually learn something.
|
|
|
|
|
True, but I always remember back in the days when I had many courses and used to be stuck on one program trying to figure out what the error is and try to solve it, that took some time which sometimes due to the exciting nature of programming made me give that program more time than the other courses. This way the guys and gals who ask can know what to do and next time they code they can use the answers as reference. I always say this Air,Food,Water, and Google are absolute necessities in life.
|
|
|
|
|
Hi can some kind person help with this JAVA Q on parsing text files:
INPUT TEXT (FASTA) FILE:
>AB485992 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
>AB485993 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
>AB485994 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
>AB485922 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
>AB485912 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
>AB485942 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
I need JAVA Code that parses the input file and generates 6 files each file contains file is labelled after the '>' and before the space ie
file 1 will be named AB485992 and that file will contain the text between the '>' and the following '>' ie:
>AB485992 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
file 2 will be labelled: AB485993 and it contents
>AB485993 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
file 3 will be labelled: AB485993 and it contents
>AB485994 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
and so on for all six files
So far I have code that parses out the word after '>' ie the file label and prints those to args file like below, can some kind person PLEASE show me how to parse the INPUT file and generate the 6 seperate files as described above each file labeled after the '>'
eg file1, labelled AB485992 and so on for the 6 files
>AB485992 some text
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
ATTGGGAATGGAGGGAAATAAATGACTGGATGGTCGCTGCT
THANKS SO MUCH!
import java.io.*;
import java.util.Scanner;
public final class ReadWithScanner {
public static void main(String... aArgs) throws FileNotFoundException {
File f = new File("args");
f.delete();
ReadWithScanner parser = new ReadWithScanner("file.text");
parser.processLineByLine();
log("Done.");
}
public ReadWithScanner(String aFileName){
fFile = new File(aFileName);
}
public final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(fFile);
try {
while ( scanner.hasNextLine() ){
processLine( scanner.nextLine() );
}
}
finally {
scanner.close();
}
}
protected void processLine(String aLine){
Scanner scanner = new Scanner(aLine);
scanner.useDelimiter(" ");
String[] fields = aLine.split(" ");
String start = ">";
if ( scanner.hasNext() ){
String name = scanner.next();
if (name.startsWith(start)){
String valueNeeded = fields[0];
String d = valueNeeded.substring(1,valueNeeded.length());
writeToLog(d);
}
}
else {
log("Empty or invalid line. Unable to process.");
}
scanner.close();
}
private void writeToLog (String fileName) {
File f = new File("args");
FileOutputStream out;
PrintStream p;
try {
out = new FileOutputStream(f, true);
p = new PrintStream( out );
p.println(fileName);
System.out.println(fileName);
}
catch (Exception e) {
System.err.println ("Error writing to file");
}
}
// PRIVATE /
private final File fFile;
private static void log(Object aObject){
System.out.println(String.valueOf(aObject));
}
private String quote(String aText){
String QUOTE = "'";
return QUOTE + aText + QUOTE;
}
}
|
|
|
|
|
I took it one step further.
import java.io.*;
import java.util.*;
public class SplitFiles {
public static void main(String[] args) throws Exception {
File mainfile = new File("MainFile.txt");
Scanner scan = new Scanner(mainfile);
ArrayList<String> List = new ArrayList<String>();
String getFileName = "";
while (scan.hasNext()) {
List.add(scan.nextLine());
}
for (int i = 0; i < List.size(); i++) {
if (List.get(i).charAt(0) == '>') {
getFileName = List.get(i).replace(">", "");
String result = "";
for (int j = 0; j < getFileName.length(); j++) {
if (getFileName.charAt(j) == ' ') {
result = getFileName.substring(0, j);
break;
}
}
File output;
if (new File(result + ".txt").exists()) {
BufferedWriter out = new BufferedWriter(new FileWriter(
result + ".txt", true));
out.write(List.get(i) + "\n");
int k;
for (k = i + 1; k < List.size(); k++) {
if (List.get(k).charAt(0) == '>')
break;
else {
out.write(List.get(k) + "\n");
}
}
out.close();
} else {
output = new File(result + ".txt");
PrintWriter out = new PrintWriter(output);
out.println(List.get(i));
int k;
for (k = i + 1; k < List.size(); k++) {
if (List.get(k).charAt(0) == '>')
break;
else {
out.println(List.get(k));
}
}
out.close();
}
}
}
}
}
Good Luck
|
|
|
|
|
Thanks so much for your help!
Just one small point the code you wrote here "for (k = i+1; k " is missing the end part any chances you know what the ending should be?
Thanks again!
|
|
|
|
|
Yes that happens with < > in code, I corrected it.
|
|
|
|
|
Thanks so much!
I tried compiling and I am getting complaints as follows, any ideas? Sorry I am new to JAVA and cant figure out how to fix it.
thanks again!
SplitFiles.java:24: cannot find symbol
symbol : method charAt(int)
location: class java.lang.Object
if (List.get(i).charAt(0) == '>')
^
SplitFiles.java:27: cannot find symbol
symbol : method replace(java.lang.String,java.lang.String)
location: class java.lang.Object
getFileName = List.get(i).replace(">", "");
^
SplitFiles.java:52: cannot find symbol
symbol : method charAt(int)
location: class java.lang.Object
if (List.get(k).charAt(0) == '>')
^
SplitFiles.java:74: cannot find symbol
symbol : method charAt(int)
location: class java.lang.Object
if (List.get(k).charAt(0) == '>')
|
|
|
|
|
Steps:
1. Copy the code into your Java project.
2. Create a Text file called MainFile.txt containing what you wanted in the first post.
It should work since I corrected the < and > (HTML problem) in my answer post.
|
|
|
|
|
It works, thank you so much!
|
|
|
|
|
Requirements of the program:
1) Write a Java Application that uses repetition and switch statements to print the song "The Twelve Days of Christmas."
2) One switch statement should be used to print the day (i.e. "first", "second", etc.) A separate switch statement should be used to print the remainder of each verse.
3) Show the song in a dialog box with a test area and a scroll bar instead of in the console. Code for this requirement is given as follow:
[CODE]
JTextArea songArea = new JTextArea(20, 30);
JScrollPane scroller = new JScrollPane(songArea);
songArea.setText(songString);
JOptionPane.showMessageDialog(null, scroller, "Twelve Days of Christmas",
JOptionPane.PLAIN_MESSAGE);
[/code]
Here is what I have which doesn't meet all of the requirements
[CODE]
//Ravi Shah
//CIS 226
//Assignment5: 12 Days of Christmas
//10/08/09
public class ChristmasSong {
public static void main(String[] args) {
// TODO Auto-generated method stub
int number;
String prize = "";
String day = "";
String song = "";
System.out.print("");
number = 12;
System.out.println();
for (int j = 1; j <= number; j++)
{
switch (j)
{
case 1:
day = "First";
prize = "A Partridge in a Pear Tree \n ";
break;
case 2:
day = "Second";
prize = "\nTwo turtle doves, \nAnd " + prize;
break;
case 3:
day = "Third";
prize = "\nThree French Hens," + prize;
break;
case 4:
day = "Four";
prize = "\nFour Calling Birds," + prize;
break;
case 5:
day = "Five";
prize = "\nFive Golden Rings," + prize;
break;
case 6:
day = "Six";
prize = "\nSix Geese a Laying," + prize;
break;
case 7:
day = "Seven";
prize = "\nSeven Swans a Swimming," + prize;
break;
case 8:
day = "Eight";
prize = "\nEight Maids a Milking," + prize;
break;
case 9:
day = "Nine";
prize = "\nNine Ladies Dancing," + prize;
break;
case 10:
day = "Ten";
prize = "\nTen Lords a Leaping," + prize;
break;
case 11:
day = "Eleven";
prize = "\nEleven Pipers Piping," + prize;
break;
case 12:
day = "Twelve";
prize = "\n12 Drummers Drumming," + prize;
break;
}
song +="\nOn the " + day + " day of Christmas \nmy true love sent to me: " + prize;
}
System.out.println(song);
}
}
[/code]
|
|
|
|
|
Have you given any thought of at least trying to do your own homework first?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
I did write that code myself. I followed the example of switch statement from the book which included "break". so i included break in my program too.
|
|
|
|