Java Programming
Would you like to react to this message? Create an account in a few clicks or log in to continue.


here you can ask help for your java related problems
 
HomeLatest imagesSearchRegisterLog in

 

 my source code

Go down 
AuthorMessage
Ak
Java Freak
Java Freak
Ak


Posts : 23
Join date : 2009-02-07

my source code Empty
PostSubject: my source code   my source code EmptySat Feb 07, 2009 2:14 pm

Code:

import java.io.*;
import javax.swing.JOptionPane;
public class Main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        int number[] = new int[5];
        int index1, index2 = 0;
        int x =0;
        int answer = 0;
        boolean found = false;

        try
        {
        for(index1 = 0; index1 < number.length; index1++)
        {
                System.out.print("Enter a number: ");
                number[index1] = Integer.parseInt(reader.readLine());
        }
        System.out.println("you entered: " + number[0] + " " + number[1] + " " + number[2] + " " + number[3] + " " + number[4]);
        System.out.print("Choose a number to search for the index location: ");
        answer = Integer.parseInt(reader.readLine());
        for(index2 = 0; index2 < number.length; index2++)
        {
            if(number[index2]==answer)
              {
                  x = index2;
                  found = true;
              }
        }
        if(found == true)
        {
            System.out.println("the value you choosed found at index: " + x);
        }
        else
        {
            System.out.println("cannot find specified value");
        }
    }
        catch(NumberFormatException e)
        {
            JOptionPane.showMessageDialog(null, e.getMessage());
            System.exit(0);
        }
    }

}
Back to top Go down
https://javafreak.board-directory.net
 
my source code
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Java Programming-
Jump to: