JAVA

PART -A

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7

PART-B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

 
  
 
 
 
 4.Write java program to demonstrate method overloading to generate random numbers, random alphabet sequence and random strings.  

import java.util.Random;
public   class p4{
 public static void main(String arg[]){
            RandomNum Rn=new RandomNum();
            Rn.generate(5);
            Rn.generate('a');
            Rn.generate(10,'a');
        }
        }

class RandomNum{
 String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
void generate (int N)
{
 System.out.println("Generate Random Number  :");
    Random random = new Random();
   int length = N;
    for(int i = 0; i < length; i++) {      
      int index = random.nextInt(alphabet.length());
       System.out.println("Random Number :  " + index);
      
      }
}

void generate(char A){
 System.out.println("Generate Random Character  :");
  StringBuilder sb = new StringBuilder();   
    Random random = new Random();
     int length = 5;
    for(int i = 0; i < length; i++) {      
      int index = random.nextInt(alphabet.length());      
      char randomChar = alphabet.charAt(index);
      System.out.println("Random alphabet sequence is: " + randomChar);
      }    
}

void generate(int N, char A)
{
 System.out.println("Generate Random  Word:");
  StringBuilder sb = new StringBuilder();
     Random random = new Random();
      int length = N;
     for(int i = 0; i < length; i++) {

      int index = random.nextInt(alphabet.length());
      char randomChar = alphabet.charAt(index);
       sb.append(randomChar);
    }
    String randomString = sb.toString();
    System.out.println("Random String is: " + randomString);
}
}