Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我在Java中遇到了很多随机数的问题,我想知道是否有人可以帮忙?我对编码相当陌生_Java - Fatal编程技术网

我在Java中遇到了很多随机数的问题,我想知道是否有人可以帮忙?我对编码相当陌生

我在Java中遇到了很多随机数的问题,我想知道是否有人可以帮忙?我对编码相当陌生,java,Java,将随机字符转换为大写,将随机字符替换为随机数字,在密码中间添加一个波浪号~字符。这是我到目前为止的作业 import java.util.Scanner; public class Main { public static void main(String[] args) { String pw; int pwl; Scanner scan = new Scanner(System.in); System.out.println("Enter your word passcod

将随机字符转换为大写,将随机字符替换为随机数字,在密码中间添加一个波浪号~字符。这是我到目前为止的作业

import java.util.Scanner;
public class Main
{
public static void main(String[] args)
 {

String pw;
int pwl;

Scanner scan = new Scanner(System.in);

System.out.println("Enter your word passcode:");
pw = scan.next();
pw = (pw.toLowerCase());
int length = pw.length();
String firstChar = pw.substring(0, 1);
String lastChar = pw.substring(length - 1);
pw = lastChar + pw.substring(1, length-1) + firstChar;
System.out.println(pw);

math.random();

 }
}
// Convert a random character to an upper case
int random = (int) (Math.random() * pw.length());
pw = pw.substring(0, random) + Character.toUpperCase(pw.charAt(random)) + pw.substring(random + 1);
System.out.println(pw);

// Replace a random character with a random digit
random = (int) (Math.random() * pw.length());
pw = pw.substring(0, random) + (int) (Math.random() * 10) + pw.substring(random + 1);
System.out.println(pw);

// Add a tilde ~ character to the middle of the passcode.
int len = pw.length();
pw = pw.substring(0, len / 2) + '~' + pw.substring(len / 2);
System.out.println(pw);