Join 300,512 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,943 people online right now. Registration is fast and FREE... Join Now!
/* Double strIneger1 = new Double(pre1); double pred1 = strIneger1.doubleValue(); Double strIneger2 = new Double(pre2); double pred2 = strIneger2.doubleValue(); Double strIneger3 = new Double(pre3); double pred3 = strIneger3.intValue(); Double strIneger4 = new Double(pre4); double pred4 = strIneger4.intValue(); Double strIneger5 = new Double(pre5); double pred5 = strIneger5.intValue(); Double strIneger6 = new Double(pre6); double pred6 = strIneger6.intValue(); Double strIneger7 = new Double(pre7); double pred7 = strIneger7.intValue(); Double strIneger8 = new Double(pre8); double pred8 = strIneger8.doubleValue(); Double strIneger9 = new Double(pre9); double pred9 = strIneger9.doubleValue(); Double strIneger10 = new Double(pre10); double pred10 = strIneger10.doubleValue(); Double strIneger11 = new Double(pre11); double pred11 = strIneger11.doubleValue(); Double strIneger12 = new Double(pre12); double pred12 = strIneger12.doubleValue(); Double strIneger13 = new Double(pre13); double pred13 = strIneger13.doubleValue(); */ //start of code
int i = 0; while (i < 1) { output.write(str1); output.write(","); output.write(str2); output.write(","); output.write(str3); output.write(","); output.write(str4); output.write(","); output.write(str5); output.write(","); output.write(str6); output.write(","); output.write(str7); output.write(","); output.write(str8); output.write(","); output.write(str9); output.write(","); output.write(str10); output.write(","); output.write(str11); output.write(","); output.write(str12); output.write(","); output.write(str13); output.write("\t"); output.write(comment); output.write("\n"); i++; }
int j = 0; int pred1 = 0; int pred2 = 0; int pred3 = 0; int pred4 = 0; int pred5 = 0; int pred6 = 0; int pred7 = 0; int pred8 = 0; int pred9 = 0; int pred10 = 0; int pred11 = 0; int pred12 = 0; int pred13 = 0; //new declaration
The values of pred1 to pred13 are not getting displayed. The command to run the file is java RejectReasonMol test.csv test.txt the reults is displayed in test.txt Also the contents of test.csv are 2,2,2,2,2,2,2,3,3,3,3,3,3 2,2,2,2,2,2,3,3,3,3,2,2,2
this is a rough program, yes the strInt values are double and I wanted to compare the values with pred values, but I am not able to make them compare....because of different data types...
ya the vectors are not used....also will be implementing arrays after the raw code works.
The scenario. I have a .csv file containing numberical data mentioned in first post. I need the compare the data vertically and print the larger number. The result will be displayed in test.txt with original input data. The command to run the prog is below java RejectReasonMol test.csv test.txt
the code is horrible because I am a learner still, I will optimise the code later but as for now.... Also I would certainly like if you could give me some tips!!!!
suppose the .csv file contains th following data.. 2,2,2,2,2,2,2,3,3,3,3,3,3 2,2,2,2,2,2,3,3,3,3,2,2,2
the result is
2,2,2,2,2,2,3,3,3,3,3,3,3
if you notice the higher of the 2 vertical digits is taken.. I need the above result in the form
so how do you come out from 2 lines of results to 3 lines of output ? finding the highest values from N lines is easy but from 2 lines you end up with 3 lines
cannot find symbol symbol : method write(double) location: class java.io.BufferedWriter output.write(strInt1);
I am trying to print strInt1 output.write(strInt1); because strInt is double I cannot print it....is there a workaround ? did you try to run the code ?
cannot find symbol symbol : method write(double) location: class java.io.BufferedWriter output.write(strInt1);
I am trying to print strInt1 output.write(strInt1); because strInt is double I cannot print it....is there a workaround ? did you try to run the code ?
You haven't answer my question How can you have 3 lines of output if you want to print the highest value from 2 lines ? Because you want to print the original 2 lines ? Give me 10 minutes I'll come back with a workable solution, if my wife does not scream for me to go to bed
the answer is simple. As you may have noticed...I am taking str1 to str13 from the input file containing 2 lines od data. I then print them as it is. Then I start comparing the digit's in such a way that pred1 to pred13 store the highest value. I then just need to print Pred1 to pred 13 ...this is where the issue is....The values of pred1 to pred13 are junk values that get printed.....I suspect the conversion is not happening properly because of 2 different data types. I tried varius ways to convert string to int , int to double, etc... but all display junk values...If you are not able to understand maybe if you run the code, you will....
hey pbl, Can you optimise the code given below as it works and I am also getting the result that I want. I only want to see how to optimise codes....will help me in furthur coding.
CODE
import java.io.*; import java.util.*;
public class RejectReasonMol {
/** Creates a new instance of RankMol */ public RejectReasonMol() { } private static File inputFile; private static File outputFile;
static public void main(String[] arg) { int[] num = new int[13]; try { Scanner input = new Scanner(new File("test.csv")); PrintWriter output = new PrintWriter(new File("output.csv"));
while(input.hasNext()) { String line = input.nextLine(); output.println(line); // System.out.println(line); StringTokenizer st = new StringTokenizer(line, ","); for(int i = 0; i < 13; i++) { int x = Integer.parseInt(st.nextToken()); if(x > num[i]) { num[i] = x; } } } input.close(); for(int i = 0; i < 12; i++) { output.print("" + num[i] + ","); // System.out.print("" + num[i] + ","); } output.println(num[12]); // System.out.println(num[12]); output.close(); } catch(Exception e) { System.out.println("Exception: " + e); } } }