Results 1 to 2 of 2
Thread: need help print random digital
- 12-09-2007, 06:26 AM #1
Member
- Join Date
- Nov 2007
- Location
- boston
- Posts
- 10
- Rep Power
- 0
need help print random digital
public class randm
{
// have problem print rndn # from 0 to 9 ten by ten. thnks adv/////
public static void main(String[] args) {
int row = 10 ;
int colum = 10;
char a = 'a', z = 'z';
System.out.printf("a = %s/%d z = %s/%d " +
"'0' = %s/%d '9' = %s/%d%n",
a, (int)a, z, (int)z,
'0', (int)'0', '9', (int)'9');
System.out.println("RandomCharacter: ");
System.out.println("limit is :" + row+ " BY" +" "+ colum+ "\n");
for(int i = 0; i < 10; ++i){
for(int j = 0; j < 10; ++j)
{
char ch = getRandomCharacter(a , z);
System.out.print(ch +",");
}// end innerLoop
System.out.println();
}// end outer forLoop
System.out.println("\nRandomDigitalCharacter: ");
System.out.println("limit is :" + row+ " BY " + " " + colum +"\n");
///// somewhere here i have problem printing rand # from 0 to 9 please help/////
for(int i = 0; i < 10; ++i){ // how many line
for(int j = 0; j < 10; ++j) // how time perLine
{
int num = (int)getRandomDigitalCharacter();
System.out.print(num+",");
}// end innerLoop
System.out.println();
}// end outer forLoop
}// end main
public static char getRandomCharacter(char ch1, char ch2){
return (char) (ch1 + Math.random() * (ch2 - ch1 + 1));
} // end getRandChart
public static char getRandomDigitalCharacter(){
return getRandomCharacter('0' ,'9');
}// end getRandmD
}// end class
- 12-31-2007, 07:47 AM #2
I'm not sure what exactly your problem is. Some things to keep in mind when posting:
1) Use proper English when posting, abbreviations only restrict those who are trying to assist you.
2) State your problem specifically.
3) Any error messages you're receiving.
4) What your desired outcome is.
5) Use code tags when posting code.
If your problem is outputting a random number between 0 and 9, that's easy and judging by your code, I find it hard to believe you don't know this.
Java Code:double num = Math.random() * 10; System.out.println((int)num);
Similar Threads
-
digital sign libraries
By Shuru in forum Advanced JavaReplies: 4Last Post: 11-07-2008, 09:01 AM -
Help please in digital clock
By jaidod in forum Java AppletsReplies: 1Last Post: 04-17-2008, 05:05 PM -
random numbers without random class`
By carlos123 in forum New To JavaReplies: 4Last Post: 01-17-2008, 11:44 PM -
need help print char and digital
By lowpro in forum New To JavaReplies: 4Last Post: 12-04-2007, 08:20 AM -
Print A Pdf
By Jack in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 06:40 AM
Bookmarks