0

How do I get the correct response to print out?

import java.util.*;
import java.io.*;


public class MultipleChoiceTest {
	public static void main (String[] args) {
	Scanner input = new Scanner( System.in );
	
	String Question;
	String FirstName;
	String LastName;
	String Answer;
	
	double CorrectTotal;
	double IncorrectTotal;
	double TotalQuestions;
	double OverallTotal;
	
	
		System.out.println("Please Enter First Name: ");
		FirstName = input.next();
		System.out.println("First Name: " + FirstName);
		
		System.out.println("What code set is used for Inpatient Hospital Procedures? \nA). ICD-9-CM Vol. 3  \nB). HCPCS \nC). ICD-13 ");
		System.out.println("Please Enter You Selection:"); 
		Answer = input.next();
		System.out.printf("Your Answer is: " + Answer );
		
		if (Answer == "A")
			{System.out.println("You Are Correct!");}
		else 
			{System.out.println("You Are Incorrect");}
		
	}

}

A Is the Right Answer, but it's not coming out like that:

Please Enter First Name: 
asdf
First Name: asdf
What code set is used for Inpatient Hospital Procedures? 
A). ICD-9-CM Vol. 3  
B). HCPCS 
C). ICD-13 
Please Enter You Selection:
A
Your Answer is: AYou Are Incorrect

Edited by PDB1982: n/a

3
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Majestics
0

Your Answer is: AYou Are Incorrect

Is this the line you want to change?
What do you want it to be changed to?

if (Answer == "A")

Use the equals() method when comparing the contents of Strings. The == operator is for primitives.

Edited by NormR1: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.