Question:

Java Programming Problems.Converting a character into uppercase or lowercase?

by  |  earlier

0 LIKES UnLike

/**

* @(#)lowercasesandupper.java

*

*

* @author

* @version 1.00 2008/8/5

*/

import javax.swing.JOptionPane;

import java.io.*;

import java.util.*;

import java.lang.*;

public class lowercasesandupper {

public static void main(String[]args)

{

String message;

int i;

String letter;

char let;

message=JOptionPane.showInputDialog("E... the string: ");

message.length();

for(i=0;i<message.length();i++)

{

let = message.charAt(i);

if(let == let.toUpperCase())

{

System.out.print(""+let.toLowerCase())...

}

else

{

System.out.print(""+let.toUpperCase()...

}

}

}

}

//ERROR OF THE PROGRAM:

char cannot be dereferenced

char cannot be dereferenced

char cannot be dereferenced

 Tags:

   Report

1 ANSWERS


  1. Problem:

    Cannot invoke toUpperCase() on the primitive type char

    i) let.toUpperCase()

    ii)let.toLowerCase()

    iii)let.toUpperCase()

    Solution:

    User Wrapper Class Character

    import javax.swing.JOptionPane;

    import java.io.*;

    import java.util.*;

    import java.lang.*;

    public class lowercasesandupper {



    public static void main(String[]args)

    {

    String message;

    int i;

    String letter;

    Character let;

    message=JOptionPane.showInputDialog(&quot;E... the string: &quot;);

    //message.length();

    for(i=0;i&lt;message.length();i++)

    {

    let = message.charAt(i);

    if(let == Character.toUpperCase(i))

    {

    System.out.print(&quot;&quot;+Character.toLowerC...

    }

    else

    {

    System.out.print(&quot;&quot;+Character.toUpperC...

    }

    }

    }

    }

    hope this will help

    Cheers:)

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.