我一直在尋找這裏,似乎無法找到可以幫助我修復代碼的東西。帶有十進制座標和多個文本的System.out.printf
我想輸出pring(2.0,2.0)時,用戶輸入2和2.我註釋了我需要幫助的代碼。我想用printf來獲得我的結果。我什麼也沒得到,只有錯誤
這是我的假設,問題在於我必須在文本之間打印(2.0,2.0),但是我無法解決我的錯誤。
import java.util.Scanner;
public class prtest {
// checks to see if radom point entered by user is within rectangle
// rectangle is centered at (0,0) and has a width of 10 and height of 5
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a point with two coordinates: ");
int x = input.nextInt();
int y = input.nextInt();
double hDistance = Math.pow(x * x, 0.5f);// heigth distance
double vDistance = Math.pow(y * y, 0.5f);// vertical distance
if ((hDistance <= 10/2) && (vDistance <= 5.0/2))
System.out
.print("Point (" + x + ", " + y + ") is in the rectangle");
// System.out.printf("Point (%1f", ", " + y + ") is in the rectangle");
else
System.out.print("Point (" + x + ", " + y
+ ") is not in the rectangle");
// System.out.printf("Point (%1f", ", " + y +
// ") is not in the rectangle");
}// end main
}// end prtest
非常感謝。 – Lish
@AlishaMcDonald不客氣。 –