What's new

Help JAVA Program

jhan04

Honorary Poster
Established
Joined
Dec 22, 2014
Posts
654
Reaction
180
Points
211
Age
32
mga maser good am po baka pwede po humingi ng tulong salamat po, need lang po sa study

"create a program that generates a password consisting of 10 alphabtic characters, where the third and seventh character are alternated between uppercase and lowercase"

thanks in advance po, Godbless
 
Hello! I'd be happy to help you create a Java program that generates a password with the specified requirements. Here's a simple Java program that does this:

Java:
import java.util.Random;

public class PasswordGenerator {

    public static void main(String[] args) {
        String password = generatePassword();
        System.out.println("Generated Password: " + password);
    }

    public static String generatePassword() {
        Random random = new Random();
        StringBuilder password = new StringBuilder();

        for (int i = 0; i < 10; i++) {
            char c = (char) (random.nextInt(26) + 'a'); // generate a random lowercase letter
            if (i == 2 || i == 6) {
                c = Character.toUpperCase(c);  // convert to uppercase if it's the 3rd or 7th character
            }
            password.append(c);
        }

        return password.toString();
    }
}

In this program, we first import the Random class to generate random characters. The generatePassword method generates a 10-character password by randomly selecting lowercase alphabetic characters and converting the 3rd and 7th characters to uppercase. Finally, we display the generated password in the main method.

You can run this program in any Java IDE or compile and run it from the command line. Let me know if you need any further clarification or assistance!
 

Similar threads

Users search this thread by keywords

  1. programming
Back
Top