3
Contributors
3
Replies
26
Views
4 Years
Discussion Span
Last Post by JamesCherrill
0

Here is my attempt so far. It's is not working like the instructions above ask.

import java.util.Scanner;
public class MixedCase 
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
       String a;
       Scanner input = new Scanner (System.in);
       System.out.print("Please enter a string: ");
       a = input.nextLine();

       for (char i = 0; i < a.length(); i++)
        {            
            if ((Character.isUpperCase(a.charAt(i))) && Character.isLowerCase(a.charAt(i)))
        {
                    System.out.print("This string has both lower and upper case characters.");
        }
            else
                {
                    System.out.print("This string does not have both lower and upper case characters.");
                }
        }
    }
}
0

you have declared i as a char, you need to declare it as an int. that sould fix your problem

0

Why do you think that? Java char is a numeric 16 bit integer type, perfectly OK, and converted to int by Java whenever needed. Did you test that before posting? It may be an odd choice, but its not wrong.
It certainly won't fix his (unspecified) problem, which is caused by the logic being way off - eg the boolean expression on line 17 will alwyas return false, which presumably is not what he intended.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.