Feeding numbers into an Array

Hi, I want to feed numbers into an array but its only using the first element. In my vi users can enter a number and this number needs to be then stored in an array. Any help would be welcome. Thanks

like this maybe?
Of course you would replace the random number with a control and use an event structure to spin the loop only if the input is changed by the user, for example.
LabVIEW Champion . Do more with less code and in less time .
Attachments:
AddNumbers.png ‏2 KB

Similar Messages

  • Converting a string of numbers into an array of booleans

    For a homework assignment, I need to convert a string of numbers into an array of booleans.  The string is a bunch of random numbers (0-9) in sequence, with no spaces.  It looks something like this: 0123452348949230740329817438120947392147809231419.  I need to make it so that each even number represents a "True" boolean and so that each odd number represents a "False" boolean.  I think that I first need to convert each element of the string into a number, and then use a case structure (or something) to say, for each element of the array, "If even, then true.  If odd, then false," but I could be wrong.  Any suggestions?

    billko wrote:
    Hooovahh wrote:
    billko wrote:
    Sounds reasonable.  Think about the definition of "odd" and "even" and it will make life a lot easier. 
    I know you are trying to be vague but I'd like to give a key hint.  Use the Quotient and Remainder function.
    LOL maybe that was one of the objectives of the homework. 
    To be fair it sounds like there is more work that is needed.  A new user of LabVIEW will have a hard time figuring out how to process each character one at a time when it isn't in an array.  
    It's just that most people (me at least) stopped thinking about division with quotient and remainder after basic algebra.  I then of course changed my way of thinking when I used LabVIEW.  Still most of the time when you use division you want to know the fractional part as a decimal.  Thinking this way makes the problem more difficult then it needs to be.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • How to get input from keyboard scanner into an array

    This is probably a very basic question but I'm very new to java..
    My task is to reverse a string of five digits which have been entered using keyboard scanner.
    E.g. - Entered number - 45896
    Output - 69854
    I used the StringBuffer(inputString).reverse() command for this, but i need a more basic method to do this.
    I thought of defining an array of 5
    int[] array = new int [5];
    and then using,
    Scanner scan = new Scanner(System.in);
    to enter the numbers. But I can't figure out how to get the five input numbers into the array.
    If I can do this I can print the array in reverse order to get my result.
    Any other simple method is also welcome.

    Hey thanks for the quick reply,
    But how can I assign the whole five digit number into the array at once without asking to enter numbers separately?
    E.g. - if entered number is 65789
    Assign digits into positions,
    anArray [0] = 6;
    anArray [1] = 5;
    anArray [2] = 7;
    anArray [3] = 8;
    anArray [4] = 9;
    I'm really sorry but I am very new to the whole subject.

  • How do I convert an image file into an array?

    I am using LabVIEW v.6.0.2
    I have no NI IMAQ device or IMAQ card, also no Vision
    The image file I have can be saved as a file containing numbers relating to the picels. I want to put these numbers into an array and plot a cross section intensity chart ( I am investigating young's double slits experiment and want to see the interference fringes in graphical form).

    I'm not sure what you're asking.
    In the GRAPHICS palette, there are READ JPEG file, READ BMP file, and READ PNG file VIs. Choose one and together with DRAW FLATTENED PIXMAP and a PICTURE indicator, you can display a picture with two functions and two wires.
    If you have spreadsheet-type data and import it with READ FROM SPREADSHEET FILE (in the File I/O palette), you can plot that directly to an intensity indicator.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Putting input into an array

    I've created a java program with an array of 7 numbers. the first number indicated how many numbers will be entered.
    for ex. 6, 202, 303, 101, 303, 505, 404
    I created an array with the above examples number, and all my methods are working to compute the average, values equal to average, below average and above average.
    However, right now its not quite right because ive entered the numbers into the array manually. What i need to do is take the numbers from the input stream and enter them into the array. How do I do this? Ive been doing so much research and can't figure out how to do it/get it right.
    // shortcut, creates array manualy. need to change this to take the numbers from the standard input stream.
    int[] numbers = { 6, 202, 303, 101, 303, 505, 404};
    // position 0 holds how many numbers there are
    int howMany = 0;
    howMany = numbers[0];
    // average numbers in array
    int numHolder = 0;
    int average = 0;
    int add = 0;
    for (int i = 1; i<numbers.length; i++) {
        add = numbers[i] + add;
        average = add / howMany;
    // number of integers that is less than the average
    int lessThan = 0;
    for (int i=1; i<numbers.length; i++){
        if (numbers[i] <  average) {
            lessThan ++ ;
    // number of integers exactly equal to the average
    int equal = 0;
    for (int i=1; i<numbers.length; i++){
         if (numbers[i] ==  average) {
         equal ++ ;
    // number of integers that greater than the average
    int greaterThan = 0;   
    for (int i=1; i<numbers.length; i++){
        if (numbers[i] <  average) {
            greaterThan ++ ;
    // print the results
    System.out.println("Average Value : " + average + "\n");
    System.out.println("Number of values below the average : " + lessThan);
    System.out.println("Number of values equaling average  : " + equal);
    System.out.println("Number of values above the average : " + greaterThan + "\n");

    BufferedReader buffy = new BufferedReader(new InputStreamReader(System.in));
    String input = buffy.readLine();   
    int num = Integer.parseInt(input);
    array[somenumber] = num;You should have try/catch statements so the program does not let the client enter strings.
    Hope this helped

  • Grabbing numbers from an array of type double and outputting them into a text file

    In a program im creating i need to save some coordinates of a micropositioner i have into a text file,
    I have the coordinates saved into an array that has 6 digits of precision (6 places after the decimal point).
    I use the number to string conversion and wire that into the write to text file function in labview.  When i open the file
    the numbers that are only displayed are the ones to the left of the decimal point.  I know the number to decimal string function
    rounds the values so if i were to input 3.111111 it would only output the string "3" instead of "3.111111" . 
    So to get all the digits onto the file without rounding i multiplied the number by 10^6 but the decimal point will be lost at that point.
    Is there anyway i can convert numbers into strings without labview rounding to the nearest whole number also without having to multiply by 10^6 and without having to expect the user to know that the coordinates saved in a file are multiplied by an order of magnitude of a million ? 

    ed oh i guess i just missed that function on the pallete after i saw that the function went from number to hex, octal, etc. i assumed that the rest on that row would be some sort of conversion to a different base number, haha thanks.

  • Comparing numbers in two arrays

    OK I am making a lottery program in Java. The idea is a user enters 4 numbers, they are saved to disk. A user then starts the draw which creates 4 random numbers and compares them with the numbers a user has chosen and sees if there are any matches. Here's what I have in my Do_Draw method
    public static void Do_Draw() {
            String input;
            int Numbers[] = new int[5];
            int[] numbers = new int[4]; //array declared
            int numBalls = 4; //integer
            int[] balls = new int[numBalls];
            for (int i = 0; i < balls.length; i++) {
                balls[i] = i + 1;
            for (int i = 0; i < numbers.length; i++) {
                int drawnBall = (int)(Math.random() * numBalls);
                numbers[i] = balls[drawnBall];
                balls[drawnBall] = balls[numBalls - 1];
                numBalls--;
                System.out.print(numbers[i] + " "); //print out numbers for user to see
                try {
                    FileOutputStream assfile = new FileOutputStream("a:/draw.txt", true); //true allows the file to be appended
                    PrintStream myOutput = new PrintStream(assfile);
                    myOutput.println(numbers);
    } //end of try
    catch (IOException e) {
    System.out.println("error writing to file, please check your disk");
    System.exit(0);
    } //end of error message
    JOptionPane.showMessageDialog(null, "The draw has taken place, Thank You");
    int matches = 0;
    for (int i = 0; i < numbers.length; i++) {
    for (int j = 0; j < Numbers.length; j++) {
    if (numbers[i] == Numbers[j])
    matches++;
    System.out.print("You have matched" + matches);
    I get a repeated message at the end, I know this but it does tell me if I have any matches. It always tells me I have no matches though. It compiles fine and looks ok but I am not sure why it is not matches. Cheers for all your help

    Hmm...you are trying to match numbers in number[] to Number[], but you do not assign any numbers to Number. I ran your program an Numbers is just full of zeros, so all you need is to enter the numbers the user wants into Number array and you should be fine...if this doesnt work, feel free to write me again.

  • Numbers into textfield using boolean buttons and case structure?

    Hi!
    I'm very new to these forums, and to LabVIEW in general. I'm currently trying to implement a calculator-ish, but without the operations (+ - * /).
    I have 10 boolean buttons, named 0-9, and with these I want to basically write a sequence of numbers into a textfield. I've managed to solve the problem using an Event structure, but now i'd like to achieve the same result using a Case structure instead. The problem is that I can't identify which button has been pressed, so I can't make the program go to the correct case (0 to 9). Is there any simple solution to this that you guys could help me with? Maybe a property node that's generic for every button? I dont know
    Anyways, I'm attaching a simplified version of what I'm trying to achieve, withouh the code I don't know how to write obviously.
    Thanks for your help in advance!
    /Sebastian
    Solved!
    Go to Solution.
    Attachments:
    help.vi ‏12 KB

    Here is a way to do it: bundle the boolean values into an array, turn that into an 8 bit number and wire that to a case structure with a boolean radix
    Message Edited by jmcbee on 03-31-2009 02:29 PM
    CLA, CLED, CTD,CPI, LabVIEW Champion
    Platinum Alliance Partner
    Senior Engineer
    Using LV 2013, 2012
    Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
    Attachments:
    helpMOD.PNG ‏13 KB
    helpMOD 80.vi ‏20 KB

  • Loading a map + variables "drawn" in a txt file into an array

    hey guys, somewhat new to java, i have an assignment for school that requires me to create an "AI" that can solve a maze, easy enough. I used a 2 dimensional array for the maze, where 1 = wall, 0 = path, 3 = visited. etc, as far as the navigating goes, it's all done. The problem: i need to be able to load a maze from a file, the file looks like this:
    7 20 <-- rows/columns
    0 10 <------ start
    6 5 <---- finish
    xxxxxxxxxx  xxxxxxxxxx
    x        x            xxx      x
    x   xxxxxx      xxx     xxx
    x  xxxxxxx  xxxx  xxxxxx
    x  x            xx           xxx
    x xx     xxxxxxx  xx       x
    xxxxxoxxxxxxxxxxxxxxxSo basically i need to store the first numbers in variables so i know what size array to create and where to start solving the maze and then i somehow need to figure out a way to transofrm that drawing into an array. Was looking into parsing the text and trying to use tokens to separate it, but i honestly can't figure out how. If someone can drop a few hints or some functions i can use, i'd much appreciate it!

    Read the Java Doc API for
    FileReader
    BufferedReader
    String.split
    String.toCharArray

  • Inserting a record into an array

    I have an applet that pops up different frames when you click on a menu item. On my add a record frame I have a number of textfields and an add button. When the button is clicked it is supposed to insert the record into my array of objects that only can have 3 records. When the button is clicked however I get a null pointer exception. I want to add the record in order based on the employee number, so first I want to check to see if the first spot of the array is null and add the record in the first spot if it is. If it isn't I want to check the employee numbers and insert the the record in the correct place and make sure the array isn't full. Can someone help me out 1. Why the nullpointer exception. 2. I am not sure if my logic is correct. Below is the Code. Thanks!!
    public void insertRecord()
    if (MyEmpArray[0] == null )
    addRec(0);
    else
    for(int index =0; index <3; index++)
    if(intEmpNumber < MyEmpArray[index].intEmpNumber && MyEmpArray[3] != null )
    addRec(index);
    else
    lblErrorMessage.setText("Array is full");
    public void addRec(int index)
    MyEmpArray[index].setValues(intEmpNumber, strFirstName, strLastName, strHomePhone,
    strStreet, strCity, strState, strZip, strCountry, strWorkStreet,
    strWorkCity, strWorkState, strWorkZip, strWorkCountry, strWorkPhoneNum,
    fltNumHours, fltHourlyWage, intI, intJ, intK);
    lblErrorMessage.setText("");
    txaReport.setText("");
    ClearFields();
    }

    for(int index =0; index <3; index++)
    An array with an index from 0 to 3, contains 4 records: you should replace it with
    for(int index =0; index <2; index++)
    The check-logic is good enough, but there are two minor "bugs":
    1) even If the array is full, the for cycle will uselessly check all the records
    2) if a the employee number of intEmpNumber is > thanMyEmpArray[index].intEmpNumber the program will show up "Array is full" even if the array isn't full.
    So, I suggest to add more code to make distinction between the two cases:
    for(int index =0; index <3; index++)
    if(MyEmpArray[3] != null ) // check if there is space to add a record
    if (intEmpNumber < MyEmpArray[index].intEmpNumber) //check if the position is right
    addRec(index);
    else
    lblErrorMessage.setText("Array is full");
    break; // exit the for cicle as the array is full
    I don't know what you are programming, but I ask you: "If the new intEmpNumber is < than the intEmpNumber of an already-full-array shouldn't be the new record inserted, discarding the last one?"
    I don't know if addRec works, I'm don't know applets, buttons..:)
    Sorry for my bad english...I hope this post will help you anyway :)

  • What is the Problem in the way that I get input into an Array

    Hi Guru's,
    Im learning Java and I have written a simple program to get the input and write into an Array. The program is as follows.
    import java.util.*;
    public class ArraysSort {
         public static void main(String[] args)
              System.out.println("Enter the Number of Entries that you want to Enter");
              Scanner num = new Scanner(System.in);
              int len = num.nextInt();
              int arr[] = null;
              System.out.println(len);
              System.out.println("Enter the Numbers");
              for (int i=0;i<len;i++)
    *               *arr[i] = num.nextInt();*
              //System.out.println("The Numbers in Ascending Order are:");
              //Arrays.sort(arr);
              for (int i=0;i<arr.length;i++)
                   System.out.println(arr);
    Can anyone tell me what is wrong with the Way that I get the input. I have marked the statement in Bold for easy identification.
    Thanks a lot for all your help..

    VijaySwaminathan wrote:
    *               *arr[i] = num.nextInt();*I don't think you can just say
    int arr[] = null;and then expect it to insert? Surely first create an array like this....
    int arr[] = new int[len];

  • Pasting data into TestStand arrays

    Is there really no way to cut-and-paste values from a spreadsheet (or any other source) into an array variable in TestStand? I know I can go the other direction, but that's not helping me right now.
    I really don't want to sit here and type in 148 numbers. And I don't want to write a kludgy program to do it using a SequenceFile object.
    Surely there must be a better way...

    Currently the TestStand sequence editor does not allow you to edit selected properties as you are suggesting. As you said, the only option is to enter them manually, or create a tool that operates on a sequence file and the tool must use a path to the property that you want to edit in some way. Currently the TestStand engine does not allow the sequence editor to specify what the currently selected property is creating a tool must edit the sequence file or step and you must supply the path to the property. We hope to address this in the future.
    Scott Richardson
    Scott Richardson
    National Instruments

  • How do you "push" into an array and return array without commas?

    Hi.  In AS 3.0 I have declared an Array as a new Array();
    I would like to push objects into that array but have a text field read back the array minus the commas that are pushed by user interaction (from numbered buttons).
    For example, if the user pushes button 1 then button 4 then button 8 I would like the array to read in the text field 148 instead of 1,4,8 .
    This seems easy but I looked at the AS 3 reference and couldn't determine whether pop() would do it.

    Does the following help in any way?
    var vb:Array = new Array(1,2,3);
    trace(vb);
    trace(vb.join(""));

  • Reading from file into an array

    Hello, new to Java and we need to modify a mortgage calculator to read interest rate from a file into an array and not have them hard coded in the program. I have read many post on how to perform this but am lost on where to put the new code and format. Here is my code and I hope I posted this right.
    import javax.swing.*;                                              // Imports the Main Swing Package                                   
    import javax.swing.event.*;
    import javax.swing.text.*;                                          // Used for  Text Box Caret Position
    import java.awt.*;                                                // Imports the main AWT Package
    import java.awt.event.*;                                         // Event handling class are defined here
    import java.text.NumberFormat;
    import java.text.*;                                              // Imports the Main Text Package
    import java.util.*;                                              // Imports the Main Utility Package
    public class mortgageCalculator1 extends JFrame implements ActionListener             // Creates class mortgageCalculator
        JLabel AmountLabel = new JLabel("   Enter Mortgage Amount:$ ");                   // Declares Mortgage Amount Label
        JTextField mortgageAmount = new JTextField(10);                                     // Declares Mortgage Amount Text Field
        JButton IntandTerm1B = new JButton("7 years at 5.35%");                    // Declares 1st Mortgage Term and Interest Rate
        JButton IntandTerm2B = new JButton("15 years at 5.50%");                    // Declares 2nd Mortgage Term and Interest Rate
        JButton IntandTerm3B = new JButton("30 years at 5.75%");                    // Declares 3rd Mortgage Term and Interest Rate
        JLabel PaymentLabel = new JLabel("   Monthly Payment: ");                     // Declares Monthly Payment Label
        JTextField monthlyPayment = new JTextField(10);                          // Declares Monthly Payment Text Field
        JButton exitButton = new JButton("Exit");                              // Declares Exit Button
        JButton newcalcButton = new JButton("New Calculation");                     // Declares New Calculation Button
        JTextArea mortgageTable = new JTextArea(35,65);                         // Declares Mortgage Table Area
        JScrollPane scroll = new JScrollPane(mortgageTable);                         // Declares ScrollPane and puts the Mortgage Table inside
        public mortgageCalculator1()                                        // Creates Method
             super("MORTGAGE CALCULATOR");                              // Title of Frame
             JMenuBar mb = new JMenuBar();                                   // Cretes Menu Bar
                JMenu fileMenu = new JMenu("File");                                 // Creates File Menu
             fileMenu.setMnemonic('F');                                      // Enables alt + f to Access File Menu
             JMenuItem exitItem = new JMenuItem("Exit");                     // Creates Exit in File Menu
             fileMenu.add(exitItem);                                   // Adds Exit to File Menu
                 exitItem.addActionListener(new ActionListener()                     // Adds Action Listener to the Exit Item
                     public void actionPerformed(ActionEvent e)                     // Tests to Verify if File->Exit is Pressed
                         System.exit(0);                                // Exits the Programs when File->Exit is Pressed
                mb.add(fileMenu);                                      // Adds the File Menu
                setJMenuBar(mb);                              
         setSize(600, 400);                                        // Sets Size of Frame
            setLocation(200,200);                                         // Sets the Location of the Window  
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                                  // Command on how to close frame
         JPanel pane = new JPanel();                                   // Declares the JPanel
         pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));                          // Sets Panel Layout to BoxLayout
         Container grid = getContentPane();                               // Declares a Container called grid
         grid.setLayout(new GridLayout(4,3,5,5));                          // Sets grid Layout to GridLayout
         pane.add(grid);                                             // Adds the grid to the Panel
         pane.add(scroll);                                        // Addes the scrollPane to the Panel
            grid.setBackground(Color.yellow);                              // Set grid color to Yellow
         setCursor(new Cursor(Cursor.HAND_CURSOR));                         // Makes the cursor look like a hand
         mortgageAmount.setBackground(Color.black);                         // Sets mortgageAmount JPanel JTextField Background Color
            mortgageAmount.setForeground(Color.white);                         // Sets mortgageAmount JPanel JTextField Foreground Color
         mortgageAmount.setCaretColor(Color.white);                         // Sets mortgageAmount JPanel JTextField Caret Color
         mortgageAmount.setFont(new Font("Lucida Sans Typewriter", Font.PLAIN, 18));     // Sets mortgageAmount JPanel JTextField Font
         monthlyPayment.setBackground(Color.black);                         // Sets monthlyPayment JPanel JTextField Background Color
         monthlyPayment.setForeground(Color.white);                         // Sets monthlyPayment JPanel JTextField Foreground Color
            monthlyPayment.setFont(new Font("Lucida Sans Typewriter", Font.PLAIN, 18));     // Sets monthlyPayment JPanel JTextField Font
         mortgageTable.setBackground(Color.yellow);                         // Sets mortgageTable JTextArea Background Color
         mortgageTable.setForeground(Color.black);                         // Sets mortgageTable JTextArea Foreground Color
         mortgageTable.setFont(new Font("Arial", Font.PLAIN, 18));               // Sets JTextArea Font
         grid.add(AmountLabel);                                        // Adds the Mortgage Amount Label
         grid.add(mortgageAmount);                                   // Adds the Mortgage Amount Text Field
         grid.add(IntandTerm1B);                                        // Adds 1st Loan and Rate Button
         grid.add(PaymentLabel);                                    // Adds the Payment Label
         grid.add(monthlyPayment);                                    // Adds the Monthly Payment Text Field
           monthlyPayment.setEditable(false);                              // Disables editing in this Text Field
            grid.add(IntandTerm2B);                                        // Adds 2nd Loan and Rate Button
            grid.add(exitButton);
         grid.add(newcalcButton);                                    // Adds the New Calc Button
            grid.add(IntandTerm3B);                                        // Adds the Exit Button
         setContentPane(pane);                                          // Enables the Content Pane
         setVisible(true);                                          // Sets JPanel to be Visable
         exitButton.addActionListener(this);                                // Adds Action Listener to the Exit Button
         newcalcButton.addActionListener(this);                            // Adds Action Listener to the New Calc Button
            IntandTerm1B.addActionListener(this);                              // Adds Action Listener to the 1st loan Button
         IntandTerm2B.addActionListener(this);                              // Adds Action Listener to the 2nd loan Button
         IntandTerm3B.addActionListener(this);                               // Adds Action Listener to the 3rd loan Button
         mortgageAmount.addActionListener(this);                              // Adds Action Listener to the Mortgage  Amount Text Field
         monthlyPayment.addActionListener(this);                              // Adds Action Listener to the Monthly payment Text Field
        public void actionPerformed(ActionEvent e)                               // Tests to Verify Which Button is Pressed
            Object command = e.getSource();                                                 // Enables command to get data
            if (command == exitButton) //sets exitButton                         // Activates the Exit Button
                System.exit(0);  // Exits from exit button                         // Exits from exit button
            int loanTerm = 0;                                             // Declares loanTerm
            if (command == IntandTerm1B)                                   // Activates the 1st Loan Button
                loanTerm = 0;                                        // Sets 1st value of Array
            if (command == IntandTerm2B)                                   // Activates the 2nd Loan Button
                loanTerm = 1;                                        // Sets 2nd value of Array
            if (command == IntandTerm3B)                                   // Activates the 3rd Loan Button
             loanTerm = 2;                                        // Sets 3rd value of Array
                double mortgage = 0;                                   // Declares and Initializes mortgage
             double rate = 0;                                        // Declares and Initializes rate                                        
             double [][] loans = {{7, 5.35}, {15, 5.50}, {30, 5.75},};                 // Array Data for Calculation
                    try
                        mortgage = Double.parseDouble(mortgageAmount.getText());            // Gets user input from mortgageAmount Text Field
                      catch (NumberFormatException nfe)                          // Checks for correct number fformatting of user input
                       JOptionPane.showMessageDialog (this, "Error! Invalid input!");      // Outputs error if number is wrong format or nothing is entered
                       return;
             double interestRate = loans [loanTerm][1];                         // Sets interestRate amount
             double intRate = (interestRate / 100) / 12;                         // Calculates Interst Rate     
                double loanTermMonths = loans [loanTerm] [0];                    // Calculates Loan Term in Months
                int months = (int)loanTermMonths * 12;                          // Converts Loan Term to Months
                double interestRateMonthly = (intRate / 12);                                // monthly interst rate
             double payment = mortgage * intRate / (1 - (Math.pow(1/(1 + intRate), months)));    // Calculation for Monthly payment
                double remainingLoanBalance = mortgage;                              // Sets Reamaining Balance
                double monthlyPaymentInterest = 0;                                       // holds current interest payment
                double monthlyPaymentPrincipal = 0;                                    // holds current principal payment
                NumberFormat myCurrencyFormatter = NumberFormat.getCurrencyInstance(Locale.US);     // Number formatter to format output in table
                monthlyPayment.setText(myCurrencyFormatter.format(payment));
                mortgageTable.setText("Month\tPrincipal\tInterest\tEnding Balance\n" +                // Formats morgageTable Header
                                      "---------\t----------\t------------\t---------------------\n");
                    for (;months > 0 ; months -- )
                     monthlyPaymentInterest = (remainingLoanBalance * intRate);               // Calculation for Monthly Payment Toward Interest
                     //Calculate H = R x I
                     monthlyPaymentPrincipal = (payment - monthlyPaymentInterest);          // Calculation for Monthly Payment Toward Principal
                     //Calculate C = P - H
                  remainingLoanBalance = (remainingLoanBalance - monthlyPaymentPrincipal);     // Calculation for Reamining loan Balance
                  // Calculate R = R - C
                  // H = monthlyPaymentInterest
                  // R = remainingLoanBalance
                  // P = payment
                  // C = monthlyPaymentPrincipal
                  // I = interestRateMonthly
                  mortgageTable.setCaret (new DefaultCaret());                    // Sets Scroll position to the top left corner
                  mortgageTable.append(String.valueOf(months) + "\t" +               // Pulls in data and formats MortgageTable
                  myCurrencyFormatter.format(monthlyPaymentPrincipal) + "\t" +
                     myCurrencyFormatter.format(monthlyPaymentInterest) + "\t" +
                     myCurrencyFormatter.format(remainingLoanBalance) + "\n");
                           if(command == newcalcButton)                               // Activates the new calculation Button
                         mortgageAmount.setText(null);                         //clears mortgage amount fields
                      monthlyPayment.setText(null);                         //clears monthly payment fields
                            mortgageTable.setText(null);                              //clears mortgage table
    public static void main(String[] args)                               //This is the signature of the entry point of all the desktop apps
         new mortgageCalculator1();
    }

    OK, making a little progress but am still very confused.
    What I have is a file (int&term.dat) with three lines;
    5.75, 30
    5.5, 15
    5.35 ,7
    I have three JButtom that I what to read a seperate line and place the term in a term TextField and a rate in a Rate TextField
    I have added the following code and all it does now is output a black space to the screen; I am working with one Button and Just the rate for now to try and get it to work. I have been looking at the forums, reading the internet and several books to try and figure this out. I think I may be getting closer.
    public static void read()
        String line;
        StringTokenizer tokenizer;
        String rate;
        String term;
        try
            FileReader fr = new FileReader ("int&term.dat");
            BufferedReader inFile = new BufferedReader (fr);
            line = inFile.readLine();
            while (line != null)
            tokenizer = new StringTokenizer(line);
            rate = tokenizer.nextToken();
            line = inFile.readLine();
             inFile.close();
             System.out.println(new String());
             catch (FileNotFoundException exception)
                   System.out.println ("The file was not found.");
              catch (IOException exception)
                    System.out.println (exception);
    }

  • How do I read directly from file into byte array

    I am reading an image from a file into a BuffertedImage then writing it out again into an array of bytes which I store and use later on in the program. Currently Im doing this in two stages is there a way to do it it one go to speed things up.
    try
                //Read File Contents into a Buffered Image
                /** BUG 4705399: There was a problem with some jpegs taking ages to load turns out to be
                 * (at least partially) a problem with non-standard colour models, which is why we set the
                 * destination colour model. The side effect should be standard colour model in subsequent reading.
                BufferedImage bi = null;
                ImageReader ir = null;
                ImageInputStream stream =  ImageIO.createImageInputStream(new File(path));
                final Iterator i = ImageIO.getImageReaders(stream);
                if (i.hasNext())
                    ir = (ImageReader) i.next();
                    ir.setInput(stream);
                    ImageReadParam param = ir.getDefaultReadParam();
                    ImageTypeSpecifier typeToUse = null;
                    for (Iterator i2 = ir.getImageTypes(0); i2.hasNext();)
                        ImageTypeSpecifier type = (ImageTypeSpecifier) i2.next();
                        if (type.getColorModel().getColorSpace().isCS_sRGB())
                            typeToUse = type;
                    if (typeToUse != null)
                        param.setDestinationType(typeToUse);
                    bi = ir.read(0, param);
                    //ir.dispose(); seem to reference this in write
                    //stream.close();
                //Write Buffered Image to Byte ArrayOutput Stream
                if (bi != null)
                    //Convert to byte array
                    final ByteArrayOutputStream output = new ByteArrayOutputStream();
                    //Try and find corresponding writer for reader but if not possible
                    //we use JPG (which is always installed) instead.
                    final ImageWriter iw = ImageIO.getImageWriter(ir);
                    if (iw != null)
                        if (ImageIO.write(bi, ir.getFormatName(), new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Unable to Write Image");
                    else
                        if (ImageIO.write(bi, "JPG", new DataOutputStream(output)) == false)
                            MainWindow.logger.warning("Warning Unable to Write Image as JPEG");
                    //Add to image list
                    final byte[] imageData = output.toByteArray();
                    Images.addImage(imageData);
                  

    If you don't need to manipulate the image in any way I would suggest you just read the image file directly into a byte array (without ImageReader) and then create the BufferedImage from that byte array.

Maybe you are looking for

  • Adobe flash player won't download to my imac running Yosemite

    The download stops at 25%. I uninstalled the old Flash player and trashed all to old files, so now I have no flash player at all. Safari said I needed tp download a new version. Harry Bernard.

  • Payment Terms in MIRO should be defaulted from PO/ Scheduling Agreement

    Dear Experts, Our client requires payment terms in miro to be defaulted as the same that is in the PO or scheduling agreement. How can this be configured. The problem being faced is that the payment terms is Scheduling Agreement is 0012, where as in

  • New 5th G Ipod keeps freezing

    Is it normal for an Ipod I have had for 2 weeks to freeze 4 times out of the 8 times I have used it. I reset it each time but is that normal? It says I have the most updated software - I have I Tunes 7

  • Problem with opening ITunes Store

    I was recently was prompted to install the latest version of ITunes 7.2 So I did. BIG MISTAKE!!! After what I thought was a successful installation, now I am unable to open the ITunes Store. I can get into ITunes; just not the store! I keep getting a

  • Adobe Flash Player 11 download problem

    I have been trying to download Adobe Flash Player 11 for two days.  When the installer gets to 50% installed, I get a message to "close Internet Explorer" in order to continue.  The problem is, Internet Explorer IS closed, but it won't finish the dow