Generating random letters and numbers together
Hi, I've just started studying Java and got stuck in this exercise so can anyone help me to solve it. I can only generate letters or numbers and don't know how to make it together.
Generate 3 charater + 3 numbers:
-the first character is randomly generated from the alphabets with odd ordering in the alphabet list (A, C, E, …, Y)
-the second character is randomly generated from the alphabets with even ordering in the alphabet list (B, D, F, …, Z)
-the third character is randomly generated from alphabet list (A to Z)
-each of the three digits is random generated from 1 to 9.
Use the random method from the Maths Class.
Thank you
Re: Generating random letters and numbers together
No, we won't do your homework for you. But if you can post what you've got so far and aska specific question, that might get you some useful responses.
db
Re: Generating random letters and numbers together
alright, I've done that but in another exercise I can't run it completely so can you help me to check what's wrong with it ? Thanks.
Write a JAVA program that calculates the surface area of a cylinder, C= 2( π r2) + 2 π r h, where r is the radius and h is the height of the cylinder. Allow the user to enter in a radius and a height. Format the output to three decimal places. Use the constant PI and the method pow() from the Math class.
This is what I've done:
Code :
/**
* @(#)Ex5.java
*
*
* @author
* @version 1.00 2010/3/18
*/
import Java.util Scanner;
public class Ex5 {
public static void main (String[] args)
{
Scanner input.new Scanner(System.in);
double radius,height,area;
System.out.print("Please enter the radius of the Cylinder");
radius = input.nextDouble();
System.out.print("Please enter the height of the Cylinder");
height = input.nextDouble();
area = (height*2+Match+radius)+2*Math.PI+Math.POW(radius,2);
System.out.println("The surface of the cylinder" + area);
}
}
Re: Generating random letters and numbers together
Well your fomula is wrong. Why don't you make it like it is written in the question and see if that works? As for formatting to 3 decimal places check this out.
http://www.javaprogrammingforums.com...al-places.html
Actually your formula is very wrong just so you know π r(squared) is pi * radius(squared) not pi+radius squared your better off googling surface of cylinder or something.