字符串判斷 是否相等 須要用 equals("須要判斷的字符") 或 用 CharAt(0)== '須要判斷的字符'java
列子以下:ip
import java.util.*;字符串
public class snippet
{input
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println( "input cost : " );
double cost = input.nextFloat();
System.out.println( "input sale type : " );
String sale_type = input.next();
System.out.println( "input tax type : " );
String tax_type = input.next();
input.close();
if ( sale_type.equals("s"))
cost = cost - cost * 0.25 ;
else
System.out.println("No sale");
if ( tax_type.charAt(0) == 'h')
cost = cost + cost * 0.13 ;
else if ( tax_type.contentEquals("g"))
cost = cost + cost * 0.07 ;
else
System.out.println( "No tax" );
System.out.println("Cost is " + cost + " sale_type is " + sale_type + " tax_type is " + tax_type);
}class
}import