Inverting OpAmp with reference voltage
In the negative feedback configuration, the op amp will drive its output such that the voltage between its positive and negative inputs is (ideally) zero.  In the first example, the positive input is at 3V. Therefore the op amp will drive the negative input to 3V.  So R1 will have 2V across it, and therefore 2mA through it; this 2mA all flows through R2 (no current flows into input because an ideal op amp has infinite input impedance), so there is 4V drop across R2. Therefore the output is 3V - 4V = -1V.  Apply the same reasoning in the second example. 

You can solve for the output voltage symbolically by summing the currents at the negative input:

$$
\frac{V_3-V_4}{R_1} + \frac{V_{out}-V_4}{R_2} = 0
$$