Hello! Just started to learn Java, here's my code (very bad i know ._.)
package recurrencerelations;
import java.util.*;
public class RecurrenceRelations {
public static void main(String[] args) {
int startValue, endValue;
String userInput;
ArrayList userInputArray = new ArrayList();
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to Recurrence Relation! "
+ "please type the operations you want");
userInput = scan.nextLine();
System.out.println("Now type in the initial value");
startValue = scan.nextInt();
System.out.println("Now type the finishing value");
endValue = scan.nextInt();
String[] result = userInput.split("\\s+");
int recurValue = startValue;
for(int i = 0; i <= endValue; i ++) {
System.out.println("Term " + i + ": " + recurValue);
for (int j =0; j < result.length; j++) {
if(result[j].charAt(1) == '-') {
switch (result[j].charAt(0)) {
case '+':
recurValue += -Integer.parseInt(result[j].substring(2));
//System.out.println("Term " + i + ": " + recurValue);
break;
case '-':
recurValue -= -Integer.parseInt(result[j].substring(2));
//System.out.println("Term " + i + ": " + recurValue);
break;
case '*':
recurValue *= -Integer.parseInt(result[j].substring(2));
//System.out.println("Term " + i + ": " + recurValue);
break;
case '/':
recurValue /= -Integer.parseInt(result[j].substring(2));
//System.out.println("Term " + i + ": " + recurValue);
break;
default:
//System.out.println("Not a valid operation, the system will close now");
break;
}
} else {
switch (result[j].charAt(0)) {
case '+':
recurValue += Integer.parseInt(result[j].substring(1));
//System.out.println("Term " + i + ": " + recurValue);
break;
case '-':
recurValue -= Integer.parseInt(result[j].substring(1));
//System.out.println("Term " + i + ": " + recurValue);
break;
case '*':
recurValue *= Integer.parseInt(result[j].substring(1));
//System.out.println("Term " + i + ": " + recurValue);
break;
case '/':
recurValue /= Integer.parseInt(result[j].substring(1));
//System.out.println("Term " + i + ": " + recurValue);
break;
default:
System.out.println("Not a valid operation, the system will close now");
break;
}
}
}
}
}
}