icabit

exercise 1

Jun 26th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. public class arg1
  3. {
  4.                 static BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
  5.         public static void main(String args []) throws IOException
  6.         {
  7.             System.out.print("enter size of array: ");
  8.             int x= 0;
  9.             x=Integer.parseInt(in.readLine());
  10.             int c=0;
  11.             c=x%2;
  12.             if (c==0){
  13.                 System.out.print("size of array is not a odd number");
  14.             }
  15.             else{  
  16.             int [] p= new int [x];
  17.             for(int y=0;y<x;y++)
  18.             {
  19.                 System.out.print("enter element for array#"+(y+1)+": ");
  20.                 p[y]=Integer.parseInt(in.readLine());
  21.             }
  22.             int o = p.length;
  23.             System.out.println("**********************");
  24.             int t = 0;
  25.             t=  o/2;
  26.             System.out.println("median: "+p[t]);
  27.             }  
  28.         }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment