error message: variable might not have been initialized
807598Feb 13 2006 — edited Feb 14 2006i am doing java programming and keep getting error messages: variable might not have been intitialized, the variables are 'one', 'two', and 'three' and they are each but at the very beginning i already had typed in String one,two,three...how do i fix this? this is part of my program:
public class Titles
{
public static void main(String[] args)
{
String book1,book2,book3,the,a,first3,first,ffirst3,ffirst,fffirst3,fffirst,one,two,three;
System.out.println("Enter the title of the first book");
book1=IO.readString();
book1=book1.trim();
System.out.println("Enter the title of the second book");
book2=IO.readString();
book2=book2.trim();
System.out.println("Enter the title of the third book");
book3=IO.readString();
book3=book3.trim();
the="the ";
a="a ";
first3=book1.substring(0,4);
ffirst3=book2.substring(0,4);
fffirst3=book3.substring(0,4);
first=book1.substring(0,2);
ffirst=book2.substring(0,2);
fffirst=book3.substring(0,2);
if (first3==the)
{
book1=book1.substring(4);
}
else
{
book1=book1.substring(0);
}
if (ffirst3==the)
{
book2=book2.substring(4);
}
else
{
book2=book2.substring(0);
}
if (fffirst3==the)
{
book3=book3.substring(4);
}
else
{
book3=book3.substring(0);
}
if (first==a)
{
book1=book1.substring(2);
}
else
{
book1=book1.substring(0);
}
if (ffirst==a)
{
book2=book2.substring(2);
}
else
{
book2=book2.substring(0);
}
if (fffirst==a)
{
book3=book3.substring(2);
}
else
{
book3=book3.substring(0);
}
int comp=book1.compareToIgnoreCase(book2);
int comp1=book1.compareToIgnoreCase(book3);
int comp2=book2.compareToIgnoreCase(book3);
if (comp<0 && comp1<0)
{
one=book1;
}
else if (comp>0 && comp1>0)
{
three=book1;
}
else
{
IO.reportBadInput();
}
if (comp2>0 && comp1<0)
{
two=book3;
}
else if (comp2<0 && comp1<0)
{
three=book3;
}
else
{
IO.reportBadInput();
}
if (comp2<0 && comp>0)
{
one=book2;
}
else if (comp2>0 && comp<0)
{
three=book2;
}
else if (comp2<0 && comp<0)
{
two=book2;
}
else
{
IO.reportBadInput();
}
if (comp1>0 && comp2>0)
{
one=book3;
}
if (comp1<0 && comp>0)
{
two=book1;
}
IO.printString(one);
IO.printString(two);
IO.printString(three);