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

Recommended Answers

All 2 Replies

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.

NormR1 Right. Here is the syntax

Answer.equals("A")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.