java ignore case problem?

java ignore case problem?
I’m trying to ignore when the user inputs uppercase letters and I tried out my code by typing a word into the program with uppercase but it doesnt convert it and it just goes to my message saying “please enter the word correctly”
can anyone help me with this

import java.util.*;

public class sport
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{

double quantity; // Declare variables
double setup;
int demand;
double inventory;

String products;

System.out.println(“Welcome to the sport program.”);
System.out.println();
System.out.println(“Please enter the sport name: “);
products = console.next();
if (products.equalsIgnoreCase(“football”)){
String products = products.toLowercase;
System.out.println(“Input the demand rate: “);
}
else
System.out.println(“You entered ” + products);
System.out.println(“Please enter the product name correctly!”);

}
}

Best answer:

You have several problems:

1) String products = products.toLowercase;

This is wrong, you do not use “String” again, you already declared the variable ‘products’ above. Now your simply trying to do an assignment, it should be :
products = products.toLowerCase();

2) “toLowercase” needs to be capitalized & needs parentheses () because its a method.

use “.toLowerCase()” instead.

3) Lastly you need to use brackets{} around your if/else statement if its more than 1 line.

if ( products.equalsIgnoreCase(“football”) )
{
String products = products.toLowercase;
System.out.println(“Input the demand rate: “);
}//end if

else
{
System.out.println(“You entered ” + products);
System.out.println(“Please enter the product name correctly!”);
} //end else

Otherwise
System.out.println(“Please enter the product name correctly!”);
will execute every single time…. Good Luck

Tags: , , ,

Under Forum

Leave a Comment for java ignore case problem?

You must be logged in to post a comment.

Trackback this post  |  Subscribe to the comments via RSS Feed


Categories