# How to create this if many inputs?

• 05-15-2008, 06:48 PM
sarahannel123
How to create this if many inputs?
Helo, I wanna try to input 1,000 samples of 5 digits numbers so that they all can pass through this equation one by one to calculate the output, y.

y=(2x/4000)-1

Below is the samples, x looks like(any random 5 digits samples is ok, as far it can get correct):

18349
32456
95332
12373
42567
12456
92434
62435
52324
48349
18349
blah..
until one thousands sample numbers

Is it possible to write a Java program of this instead of excel?
The problem is how to create a Java program that can accept so many inputs at one time ?
• 05-15-2008, 07:29 PM
sukatoa
Here is a quick sample....

Code:

```public test(){     //Sample inputs limited to 800 to see the whole input     for(int x=0; x<800;x++){         int t = new java.util.Random().nextInt(100000);         if(t>9999){ //Filter those inputs that are less than 10000.               System.out.println("Input: "+t+"\t Y = "+(((2*t)/4000)-1));         }            } }```
• 05-18-2008, 03:41 PM
sarahannel123
Hi, sukatoe, thanks for the reply. However, "not random function".
Ignore the random as what I mean is have a list of sample data,

Now, I have saved my list of 1000s samples into a text format file
18349
32456
95332
12373
42567
12456
92434
62435
52324
48349
18349
blah..
until one thousands sample numbers
I would need a java program that can make every sample that pass through this formulae:
y=(2x/4000)-1

to get the output answers automatically one by one. Can you guide me how to do it?
Thanks.
• 05-18-2008, 04:22 PM
sukatoa
You may use Scanner class to capture the values from a text file....

Code:

```private static final getSamples() throws Exception{       ArrayList<Object> list = new ArrayList<Object>();       Scanner read = new Scanner(new File("samples.txt"));       while(read.hasNext())             list.add(read.next());       read.close();       return list; }```
You can test the code....

For calculations, same as my first example, take a loop from the returned list

After every calculation, show also the answer directly....