Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java System.out.printf,带十进制坐标和多个文本_Java_Printf - Fatal编程技术网

Java System.out.printf,带十进制坐标和多个文本

Java System.out.printf,带十进制坐标和多个文本,java,printf,Java,Printf,我一直在这里搜索,似乎找不到什么可以帮助我修复代码 当用户输入2和2时,我试图让输出弹簧(2.0,2.0)。我注释掉了需要帮助的代码。我想使用printf来获得结果。除了错误,我什么也得不到。 我的假设是,问题在于我必须在文本之间打印(2.0,2.0),但是我无法解决我的错误 import java.util.Scanner; public class prtest { // checks to see if radom point entered by user is within

我一直在这里搜索,似乎找不到什么可以帮助我修复代码

当用户输入2和2时,我试图让输出弹簧(2.0,2.0)。我注释掉了需要帮助的代码。我想使用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
import java.util.Scanner;
公共类PRT测试{
//检查用户输入的radom点是否在矩形内
//矩形以(0,0)为中心,宽度为10,高度为5
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(System.in);
System.out.print(“输入一个带有两个坐标的点:”);
int x=input.nextInt();
int y=input.nextInt();
双hDistance=Math.pow(x*x,0.5f);//高度距离
双V距离=数学功率(y*y,0.5f);//垂直距离

如果((hDistance您以错误的方式使用了
System.out.printf
方法。您的方法应该像这样使用它:

System.out.printf("Point (%.1f, %.1f) is in the rectangle", x*1.0, y*1.0);
//...
System.out.printf("Point (%.1f, %.1f) is not in the rectangle", x*1.0, y*1.0);
或者更好的是,可以将点作为整数处理

System.out.printf("Point (%d, %d) is in the rectangle", x, y);
//...
System.out.printf("Point (%d, %d) is not in the rectangle", x, y);

了解og
System.out.printf用法的更多信息:

以下内容似乎适合我

System.out.printf(“点,(“%1.1f”,“1.1f”)在矩形中,”(双)x,(双)y)