import java.io.*;
import java.util.Random;
import java.util.*;
class Program4
{
public static void main(String args[])
{
// creating instances of Random class
Random r = new Random();
Random r1 = new Random();
StringBuilder sb = new StringBuilder();
for(int i=0;i<5;i++)
{
// Generating random integers
int num = r.nextInt(1000);
overload(num);
// Generating Random doubles
double d = r1.nextDouble();
overload(d);
char c = (char)(r1.nextInt(26) + 'a');
//System.out.println("Random Number: "+Math.random());
sb.append(c);
overload(c,sb);
}
}
public static void overload(int num)
{
System.out.println("Random Integer: "+num);
}
public static void overload(double d)
{
System.out.println("Random Double: "+d);
}
public static void overload(char c, StringBuilder sb)
{
System.out.println("Random Alphabet: "+c);
System.out.println("Random String is: " + sb);
}
}
Search This Blog
Wednesday, 1 September 2021
4. Write java program to demonstrate method overloading to generate random numbers, random alphabet sequence and random strings.
Labels:
New_Java_Programs
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment