-1
我試圖創建一個Java程序,它從文本文件中讀取一行中的三個數字,並將它們解釋爲三角形的三條邊的長度,然後打印出:創建一個讀取.txt並識別三角形邊長的Java程序
"Equilateral" - if the three lines are equal length
"Isosceles" - if only two of the three lines are equal
"Scalene" - for any other valid length
...or "Not a Triangle"
我的文本文件看起來像這樣...
1 1 1
2 2 1
2 x 3
到目前爲止,我有這個,不知道去哪裏從那裏任何幫助,將不勝感激謝謝!
import java.util.Scanner;
import java.io.File;
import java.util.NoSuchElementException;
import java.io.FileNotFoundException;
public class Triangle {
public static void main (String[] args){
File fileName = new File("input.txt");
Scanner scan = null;
try {
Scanner file = new Scanner(new File("input.txt");
}
while(scan.hasNextLine()) {
}
catch(FileNotFoundException){
}
如果你需要一些解釋請評論 – sjboss
感謝sjboss,這有很大幫助。之前沒有使用過Interger.parseInt,但查找了那些我沒有見過的部分,並且它們一起來了。再次感謝。 – JESbashingwitya