Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Basics: Why won't this return a character from the ASCII table?

807580Dec 20 2009 — edited Dec 20 2009
Hello all,

I am working on a project. Right now I am in stage one of development, and already I have fallen into a dilemma. I cannot figure out why this code will not return a character value. If you look closely, I am trying to generate a random number from 65 to 90, and then convert that number to the proper ASCII character. Let me know your thoughts, thanks!

import java.util.*;
import java.lang.*;

class Liscense
{
public static int Randomchar()
{
int charFive = 65 + (int) (Math.random()*90);

return (char) charFive;
}



public static void main (String [] args)
{
double y = Math.random()*1000;
double x = Math.random()*1000;

System.out.println(("x: ") + y);
System.out.println(("y: ") + x);
System.out.println(Randomchar());

System.out.println(x + y);
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 17 2010
Added on Dec 20 2009
5 comments
289 views