Hello,
I'm facing an issue while playing with BufferedWriter: got a loop with ten
iterations. Debugging through the console via System.out.println, I can see
the 10 lines it was supposed to display. But when I call the
BufferedWriter'
I'm not sure where the problem is. Can anyone help me with a workaround?
Current Output:
> Case #1: 2 3
Case #2: 1 4
Case #3: 4 5
Case #4: 29 46
Case #5: 11 56
Case #6: 4 5
Case #7: 40 46
Case #8: 16 35
Case #9: 55 74
Desired Output:
> Case #1: 2 3
Case #2: 1 4
Case #3: 4 5
Case #4: 29 46
Case #5: 11 56
Case #6: 4 5
Case #7: 40 46
Case #8: 16 35
Case #9: 55 74
Case #10: 7 9
import java.io.BufferedRea
>
> import java.io.BufferedWri
>
> import java.io.File;
>
> import java.io.FileReader;
>
> import java.io.FileWriter;
>
> import java.io.IOException
>
> import java.util.ArrayList
>
>
>>
>> public class A1 {
>
> static int count=1;
>
> public static void main(String[
>
> new A1().start(args[
>
> }
>
> public void start(String s){
>
> try {
>
> File f = new File(s);
>
> FileReader fr;
>
> fr = new FileReader(f)
>
> BufferedReader br = new BufferedReader(
>
> int cases = Integer.parseInt(
>
> File fw = new File("output.
>
> f.createNewFile(
>
> FileWriter fwr = new FileWriter(fw)
>
> BufferedWriter bw = new BufferedWriter(
>
> ArrayList<Integer> items = new ArrayList<Integer>
>
> ArrayList<String> result = new ArrayList<String>
>
> for (int i = 0; i<cases; i++){
>
> items.clear(
>
> int money = Integer.parseInt(
>
> Integer.parseInt(
>
> for (String r: br.readLine(
>
> try{
>
> items.add(Integer.
>
> } catch (Exception e) {;
>
> e.printStackTrace(
>
> }
>
> }
>
> result.add((
>
> }
>
> fr.close();
>
> for (String x: result){
>
> bw.flush();
>
> bw.write(x);
>
> }
>
>
>> } catch (IOException e) {
>
> e.printStackTrace(
>
> }
>
> }
>
>
>> public String doCalc(int c, ArrayList<Integer> a){
>
> String msg = "";
>
> for(int i=0;i<a.size(
>
> for(int j=i+1;j<a.size(
>
> if ((a.get(i) + a.get(j))== c){
>
> msg += "Case #" + count + ": " + (i+1) + " " + (j+1) + "\n";
>
> // System.out.println(
>
> count++;
>
> break;
>
> }
>
> }
>
> if (!msg.isEmpty(
>
> break;
>
> }
>
> return msg;
>
> }
>
> }
>
>
>
First lines of the input file:
10
>
> 100
>
> 3
>
> 5 75 25
>
> 200
>
> 7
>
> 150 24 79 50 88 345 3
>
> 8
>
> 8
>
> 2 1 9 4 4 56 90 3
>
>
Chris
[Non-text portions of this message have been removed]
Java Official Group is created for the following topics: Java 2 Enterprise Edition - J2EE, Java 2 Standard Edition - J2SE, Java 2 Micro Edition - J2ME, XML, XSL, XSD, XPATH, Web Services, Jini, JXTA for all type of Java Geeks.
Whoever posts spam / ads / job related message will be BANNED IMMEDIATELY
No comments:
Post a Comment