현재 나의 목표는 분수를 파싱하고 부적절한 분수를 만드는 것입니다. 예를 들어 :분수 파싱
1_1/3 + 5/3
과 같이 콘솔에 와야한다
4/3 + 5/3
누군가가 제가 오른쪽에 갈거야 말할 수 방향과 무엇에 집중해야합니까?
import java.util.Scanner;
public class FracCalc {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Welcome to FracCalc");
System.out.println("Type expressions with fractions, and I will evaluate them.");
boolean isTrue = true;
String in = "";
while(isTrue) {
in = input.nextLine();
if (in.equals("quit")) {
System.out.println("Thanks for running FracCalc!");
isTrue = false;
}else{
System.out.println("You asked me to compute" + in);
}
}
}
public static void parse(String in){
int underscore = in.indexOf("_");
int slash = in.lastIndexOf("/");
String wholenumber = in.substring(0, underscore);
String numerator = in.substring(underscore + 1,slash);
String denominator = in.substring(slash + 1);
if (underscore<0 & slash<0) {
in = wholenumber;
} else if (underscore<0 & slash>0) {
in = in;
} else if (underscore>0 & slash>0) {
} else if (underscore>0 & slash<0) {
in = "Error";
}
}
}
나는 그 문자열을'.split ("_")'이라고 말하고 자동으로 양쪽을 한꺼번에 처리한다고합니다. – ChiefTwoPencils
당신의 문제는 무엇입니까? – Tetramputechture
우리는 .split ("_")에 대해 알지 못했습니다.} else if (밑줄> 0 및 슬래시> 0) {그리고 System.out.println에서도 "당신이 계산 해달라고 부탁했습니다.") 구문 분석으로 대체하려고 시도했지만 작동하지 않습니다. –