I am taking my first class in Java and am having problems with converting lowercase letters to uppercase and am not having success. The program compiles and executes. However, the lowercase letters input by the user are not converted to uppercase.

I think the problem is very simple, but I can't see it. Does anyone have a suggestion?

Dehatim

/**    
  This program reads a string of lowercase letters typed on the  
  keyboard, converts them to uppercase letters, and displays 
  them.
*/ 
// Import necessary classes.
import java.util.Scanner;
// Start main part of program.
 
public class CaseConversion
{ 
     public static void main(String[] args) 
    { 
   
    // Create a scanner keyboard to accept input from the keyboard.
   
    Scanner keyboard1 = new Scanner(System.in);
         
    // Ask user to type lowercase alphabet.
   
   System.out.println("Welcome to Letter Conversion!\n");
   System.out.println("Enter the letters of the alphabet in 
        lowercase");           

    // Read in user entry.
     
    String word1 = keyboard1.next( );
     
    [B]// Find out what's in the string.
        
    word1.substring(0, 26);
     
    // Convert input into uppercase letters.
     
    String word2 = word1.substring(0, 26);
              
     word2.toUpperCase();
     
     // Output the result.
          
     System.out.println("The alphabet is now is [/B]
[B]          uppercase:\n"  +  [/B][B]word2);
[/B]        
 }  // end of main()
 
}  // end of class CaseConversion

I have figured out the answer to the problem, which was remarkably simple.

System.out.println("Welcome to Letter Conversion!\n");
     System.out.println("Enter the letters of the alphabet in lowercase with no spaces between:"); 
          
     // Read in user entry.
     
     String word1 = keyboard1.next( );                   
          
     // Output the result.
          
[B]     System.out.println("The alphabet is now is uppercase:" + "\n" + word1.toUpperCase() + "\n");
[/B]

I needed to put "word1.toUpperCase()" in the System.out.println statement.

} // end of main()

} // end of class Timpko_Ch2_8 (formerly CaseConversion)

u can just try dis code,..

import java.io.*;
import java.lang.*;

public class CharToLowercase{
public static void main(String args[]) throws IOException{
BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the uppercase character:");
String s = buff.readLine();
char c = s.charAt(0);
char lower = Character.toLowerCase(c);
System.out.println("Lowercase character: " + lower);
}
}

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.