-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinCalc.java
More file actions
41 lines (30 loc) · 1.1 KB
/
LinCalc.java
File metadata and controls
41 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package labb3;
import java.util.Scanner;
import java.util.InputMismatchException;
import lincalc.LinCalcJohn;
public class LinCalc {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("LinCalc, mata in matematiska uttryck: ");
String uttryck = scan.nextLine();
String[] result = Lek(uttryck);
// String[] operander =
for (int i = 0; i < result.length; i++) {
System.out.println(result[i]);
}
}
static String[] Lek(String _uttryck){
_uttryck = _uttryck.replaceAll("\\s", ""); //Tar bort alla "whitespaces"
_uttryck = _uttryck.replaceAll(",", "."); // Byter ut alla punkter mot komman
// _uttryck = _uttryck.replaceAll("-", "+-"); // Byter ut alla - mot +-
// _uttryck = _uttryck.replaceAll()
String[] _result = _uttryck.split("(?<=[+*/(^)])|(?=[-+*/(^)])"); // MASTER uttryck, lookbehind(?<=), | (X or Y), lookahead (?=), character classes ([]).
return _result;
}
static char MemberOf(String list, char pos){
for(int i = 0; i < list.length(); i++){
if(list.charAt(i) == pos) return list.charAt(i);
}
return 0;
}
}