Hello everyone, I'm brand new to java and also to this forum. Hoping to get some help and maybe help others when I get better at this.
Ok, so I tried to make a loop, if you enter "y" the code is supposed to loop, otherwise the program should terminate, but for some reason it won't loop, and I can't figure out what I'm doing wrong...
import java.util.Scanner; public class scanner { public static void main (String args[]){ Scanner scn = new Scanner(System.in); Scanner go = new Scanner(System.in); int fnum, snum, answer; String yn = "y"; while(yn == "y"){ // this is there my loop starts System.out.print("enter first number: "); fnum = scn.nextInt(); System.out.print("enter second number: "); snum = scn.nextInt(); answer = fnum - snum; System.out.println(fnum + " - " + snum + " = " + answer); System.out.print("go again (y/n)? "); yn = go.nextLine(); System.out.print(yn); // just so make sure yn="y" } } }