Skip to content

Instantly share code, notes, and snippets.

@tinkerstudent
Created October 10, 2015 21:47
Show Gist options
  • Select an option

  • Save tinkerstudent/1a336c388de4f8821b7b to your computer and use it in GitHub Desktop.

Select an option

Save tinkerstudent/1a336c388de4f8821b7b to your computer and use it in GitHub Desktop.
package com.tinkeracademy.ap;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
//
public class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner s = new Scanner(new File("input.txt"));
int operand = 0;
String op = "";
int result = 0;
while (!op.equals("=")) {
operand = s.nextInt();
if (op.equals("+")) {
result = result + operand;
} else if (op.equals("-")) {
result = result - operand;
} else {
result = operand;
}
op = s.next();
}
System.out.println("result=" + result);
s.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment