This is about a java console program in which there are some string variables which are used to search records and display in the console.
When i execute this program there comes the error message:
error: variable "variable name" might not have been initialized.
I want to know how i can initialize string variables in java console program. Here is the code:
Scanner sc=new Scanner(System.in);
String customername;String cname;
String caddress;String cphone
boolean found;
System.out.println("Enter customer name to search records:");
customername=sc.nextLine();
if (customername==cname)
{
found=true;
if(found){
System.out.println("Customer name:"+cname);
System.out.println("Customer address:"+caddress);
System.out.println("Customer phone:"+cphone);}
}
}
Here i want to search records saved in a text file and display records if cname==customername
but error tells that string variable cname
it is not initialized and also for caddress
and cphone
.
What should i do to initialize string variables and how to do this?