View Single Post
Join Date: Oct 2008
Posts: 25
Reputation: shubhang is an unknown quantity at this point 
Solved Threads: 0
shubhang shubhang is offline Offline
Light Poster

Re: Need urgent help in code!

 
0
  #3
Nov 20th, 2008
When I run the program,the search part(HIGHLIGHTED) does not work.
Please tell me where I am going wrong.

import java.io.*;
import java.util.*;
class search
{
	private String str,sval;
	private String arr[]=new String[8];
	private int ch;
	private int pos,ctr;

	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	public void calc()throws IOException
	{
		BufferedReader in=new BufferedReader(new FileReader("adbk.txt"));			//file read
		//DataInputStream in=DataInputStream(new FileInputStream("adbk.txt"));
		System.out.println("How would you like to search?");
		System.out.println("1)by fn");
		System.out.println("2)by ln");
		System.out.println("3)by area code");
		System.out.println("4)by city");
		System.out.println("5)by state");
		System.out.println("enter choice:");
		ch=Integer.parseInt(br.readLine());
																							

		switch(ch)
		{
			case 1:
			{
				System.out.println("enter fn");
				pos=0;
				break;
			}
			case 2:
			{
				System.out.println("enter ln");
				pos=2;
				break;
			}
			case 3:
			{
				System.out.println("enter arcd");
				pos=3;
				break;
			}
			case 4:
			{
				System.out.println("enter city");
				pos=5;
				break;
			}
			case 5:
			{
				System.out.println("enter state");
				pos=6;
				break;
			}
			default:
			{
				System.out.println("error");
				break;
			}
		}
		sval=br.readLine();
																							//clr here
		while((str=in.readLine())!=null)
		{

			StringTokenizer st=new StringTokenizer(str,"_");
			for(int i=0;i<=7;i++)
			{
				arr[i]=st.nextToken();


			}
			System.out.println();

			if(sval==arr[pos])
			{
				ctr++;
				for(int i=0;i<=7;i++)
				{
					System.out.print(arr[i]+" ");
				}
				System.out.println("");
			}

		}

		System.out.println("Total hits="+ctr);

	}

}
Thanks.
Reply With Quote