❓ Help JAVA Program

jhan04

Honorary Poster
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!
 

About this Thread

  • 1
    Replies
  • 438
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,075
Guests online
1,007
Total visitors
2,082

Forum statistics

Threads
2,273,674
Posts
28,950,839
Members
1,234,914
Latest member
babayaga23
Back
Top