我正在尝试创建一个程序,显示任何给定点的坐标x
和y
坐标,反映在线性函数ax+b
上。但是,我收到一个运行时错误,表明它超出了范围。我知道您不能在原始数据类型上调用方法,但我不知道如何获得它。
import java.util.*;
public class ReflectivePoint {
public static void main (String[]args){
Scanner lol = new Scanner(System.in);
System.out.println("Please enter the linear function.");
//That will be in the format ax+b
String function = lol.nextLine();
Scanner lol2 = new Scanner(System.in);
System.out.println("Please enter the point.");
//That will be in the format a,b
String point = lol2.nextLine();
int a = point.charAt(1);
int b = point.charAt(3);
int m = function.charAt(1);
int c = function.charAt(4);
int x1 = (2 / (m + 1 / m)) * (c + b - a / m) - a;
int y1 = (-1/m) * x1 + a / m + b;
System.out.println(x1+", "+y1);
}
}