Friday, July 31, 2009

This is for 7 variables s1 - s7. I want to make this variable dynamic..I want it for 108 variables.?

U can run this code and see the output as an example.


import java.io.*;


import java.util.*;





class Test


{


FileOutputStream outFileStream;


PrintWriter outStream;


File outFile;


String outputFileTxt;


public static void main(String[] args) {


try{


Test t = new Test();


t.generate();


}catch(Exception e ){}


}


public int generate() throws IOException{


outputFileTxt = "C:\\My Documents\\tea.txt";


outFile = new File(outputFileTxt);


outFileStream = new FileOutputStream(outFile);


outStream = new PrintWriter(outFileStream);


int s1,s2,s3,s4,s5,s6,s7;


int r = 60;


int a1=10,a4=40,a7=70;


int counter = 0;


while(counter++!=4){


for(int i=0;i%26lt;r;i++){


s1 = a1;


s2 = s1 + i % 3;


s3 = s1;


s4 = a4;


s5 = s4 + i % 4;


s6 = a7;


s7 = s6 + i % 5; System.out.println(s1+"\t"+s2+"\t"...


}


a1 = a1 + 5;


a4 = a4 + 5;


a7 = a7 + 5;


}


return 0;


}


}

This is for 7 variables s1 - s7. I want to make this variable dynamic..I want it for 108 variables.?
the easiest solution i see is just declaring an array with a length of 107 elements...





Integer x[107];





Or try a vector! (an automatically growing linked array)


No comments:

Post a Comment