-2

Such as

Scanner keyboard = new Scanner(System.in);

String  productName1, productName2;
System.out.println("First product's info: ");
System.out.print("Product name: ");
productName1 = keyboard.nextLine();
System.out.println("");
System.out.println("Second product's info: ");
System.out.print("Product name: ");

How would I go about making it to where, when the user, per-say, types in aPPles as productName1. When i reprint it later, how would I make the system print it was Apples. User input print :aPPles reprint: Apples

DancingDylan
  • 53
  • 2
  • 4
  • 10
  • 3
    possible duplicate of [Capitalize First Char of Each Word in a String Java](http://stackoverflow.com/questions/1892765/capitalize-first-char-of-each-word-in-a-string-java) – sstan Sep 23 '15 at 23:25
  • [What have you tried?](http://mattgemmell.com/what-have-you-tried/) String class contains a lot of usefull methods like `substring` `toUpperCase` `toLowerCase`. – Pshemo Sep 23 '15 at 23:28
  • Yeah but it all seems like there had to be an easier way rather than just System.out.print("|" + productName1.substring(0, 1).toUpperCase() + productName1.substring(1) + productname1.substring(1,4) + productName1.subtring(4); – DancingDylan Sep 23 '15 at 23:33

2 Answers2

0

Use

productName1 = productName1.toLowerCase();  //To lower case
productName1 = productName1.substring(0,1).toUpperCase().concat(productName1.substring(1));

This first takes the string and makes it lower case. Then it takes the first letter, makes it uppercase and adds rest of the string to it.

DarkHorse
  • 963
  • 1
  • 10
  • 28
-1

Try this

public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);
    String  productName1;
    System.out.println("First product's info: ");
    System.out.print("Product name: ");
    productName1 = keyboard.nextLine();
    System.out.print("Product name: ");
    productName1 = productName1.toLowerCase();
    productName1 = Character.toUpperCase(productName1.charAt(0)) + productName1.substring(1);
    System.out.println(productName1);
    keyboard.close();

}
Darcy
  • 1
  • 3