Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

trouble with If statements

$
0
0
Well I've always had some problems with this, but I can't seem to find any answers.
I'm asking for you to look at the second section of code, when I run this code and reply to "so your name is (name)?" with "yes", it runs the else instead of the if.
import java.util.Scanner;
class Learn1 {
	
	public static void main(String[] args) {
		
		double chicken = 4.14159625;
		int beef = 1;
		double pie;
		pie = chicken - beef;
		System.out.print("Hello ");
		System.out.print(pie);
		System.out.println(" Worlds!");
		
		
		System.out.println("name please!");
		Scanner name = new Scanner(System.in);
		System.out.println("so your name is " + name.nextLine() + "?");
		Scanner yesno1 = new Scanner(System.in);
		if (yesno1.nextLine() == "yes"){
		System.out.println("OK!");
		}else{
		System.out.println("ah...");
		}
	}
}



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>