Solved

SIMPLE ROUTINE

Posted on 1998-02-05
2
187 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
2 Comments
 
LVL 4

Accepted Solution

by:
russgold earned 20 total points
Comment Utility
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
Comment Utility
Thanks, it was so obvious.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now