Solved

SIMPLE ROUTINE

Posted on 1998-02-05
2
220 Views
Last Modified: 2010-04-16
I have written a simple java program which does not appear to work, can anybody help...

class cat {
  public static void main(String args[])
     {
     char a,b;
     int d,e;
     d =(int)(Math.random()*3+65);
     e =(int)(Math.random()*3+65);
     a=(char)(d);
     b=(char)(e);
     System.out.println(a);
     System.out.println(b);
     if ((a=='c') && (b=='a'))
     System.out.println("OK");
     else
     System.out.println("NOT OK");
     }
  }

This generates two random characters and then prints a message accordingly, however if the characters are 'c' and 'a' then the display does not show the 'OK' message as expected.

Any suggestions.
0
Comment
Question by:RICHARDH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
russgold earned 20 total points
ID: 1232886
Your code generates upper case letters, but you are testing for lower case letters.

Instead of:

if ((a=='c') && (b=='a'))

you need:

if ((a=='C') && (b=='A'))
0
 

Author Comment

by:RICHARDH
ID: 1232887
Thanks, it was so obvious.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jdbc error in jsp application 20 74
SHA2 certs for IIS AND Java? 2 122
jboss wildfly 10.1 10 437
program arguments vs VM arguments 4 31
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question