创建随机密码给出不兼容类型错误

时间:2013-04-04 16:01:12

标签: java incompatibletypeerror

到目前为止,这是我的编码。我正在制作一个程序来帮助用户随机创建密码。我在制作随机字体时遇到问题。我想到了一种方法,但它给了我一个不兼容的错误,我试过了:

chars[] letters= "abecdefghijklmnopqrstuvwxyz".toCharArray();

这是我目前的代码。

import java.util.Random;
import java.util.Scanner;

public class Password
{
  public static void main(String [] args)
  {
    char letters;
    Scanner in = new Scanner (System.in);
    System.out.println("Please choose from the following menu options:");
    System.out.println("[1] Lowercase Letters");
    System.out.println("[2] Lowercase & Uppercase Letters");
    System.out.println("[3] Lowercase, Uppercase, and Numbers");
    System.out.println("[4] Lowercase, Uppercase, Numbers and Punctuation");
    System.out.println("[5] Quit");
    System.out.println ("Enter Selection:");
    int selection = in.nextInt();
    System.out.println("Password Length (1-14):");
    int length = in.nextInt();
    if (selection == 1)
      letters = "abcdefghisjklmnopqrstuvwxyz".toCharArray();
    Stringbuilder sb = new StringBuilder(); 

1 个答案:

答案 0 :(得分:0)

toCharArray返回char [],字母仅为char