Tuesday, March 23, 2010

Enter State-Enter Capital Then Find Capital

import java.io.*;
public class question2
{ public static void main(String args[]) throws IOException
  { question2 abc = new question2();
  abc.show();
  }
   
  void show() throws IOException
  { InputStreamReader read = new InputStreamReader(System.in);
  BufferedReader br = new BufferedReader(read);
   
  String st[] = new String[4];
  String ca[] = new String[4];
   
  for(int i=0;i<4;i++)
  { System.out.println("Enter a state");
  st[i] = br.readLine();
  System.out.println("Enter its capital");
  ca[i] = br.readLine();
  }
  System.out.println("OK!");
  System.out.println();
  System.out.println("Enter state to display its capital");
  String s = br.readLine();
  int count=0;
  for(int i=0;i<4;i++)
  { if(s.equals(st[i]))
  {System.out.println(ca[i]);
  count++;
  }}
  if(count==0)
  System.out.println("Error");
  }
}


   
   
   

No comments:

Post a Comment