Results 1 to 4 of 4
  1. #1
    sarahannel123 is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default 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 ?

  2. #2
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    Here is a quick sample....

    Java 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));
             }	
         }
    }
    Last edited by sukatoa; 05-15-2008 at 07:31 PM.
    freedom exists in the world of ideas

  3. #3
    sarahannel123 is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Default

    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.

  4. #4
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    You may use Scanner class to capture the values from a text file....

    Java 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....
    Last edited by sukatoa; 05-18-2008 at 04:31 PM.
    freedom exists in the world of ideas

Similar Threads

  1. Java program that stores user inputs
    By staticy2003 in forum Advanced Java
    Replies: 6
    Last Post: 01-24-2008, 07:46 PM
  2. Date Inputs
    By hiranya in forum AWT / Swing
    Replies: 3
    Last Post: 11-06-2007, 05:11 PM
  3. Create a new variable
    By mathias in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:48 AM
  4. how to create different arrays
    By osval in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 11:07 PM
  5. Create XML From XSD
    By Jack in forum XML
    Replies: 1
    Last Post: 07-09-2007, 12:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •