内容が異なるファイルから二重のデータを読み込もうとしています。たとえば、それが double の場合、メッセージは「Double number is 23.5」になります。倍数でない場合、メッセージは「63 は倍数ではありません」となるはずです。ファイルの内容は
97.9
100.1
三
六十三
77
12.4
3002.4
76
涼しい
34.6
これです
…………
私が書いたコードはファイルを開き、次の行をスキャンしますが、正しく動作していないようです。
class ReadDouble
{
Scanner scan = new Scanner(System.in);
try
{
File textFile = new File ("doubleData.txt");
Scanner scanFile = new Scanner (textFile);
String str = scan.nextLine();
while(scanFile.hasNextLine())
{
double num = Double.parseDouble(str);
if(str == num)
{
System.out.println("Double number is" + str);
}
}//end while
}//end try
catch (NumberFormatException nfe)
{
System.out.println(str + "Is not a Double number");
}
}
}//クラス終了