?
Solved

SIMPLE ROUTINE

Posted on 1998-02-05
2
Medium Priority
?
230 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 80 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

800 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