jeudi 24 septembre 2020

How do I save the random generated string to a variable and compute the distance?

I am taking a Java class and was tasked to create a code with these parameters:

(Get String 1 –from user) Prompt the user to enter a string consisting of 5 uppercase characters and save this string in a variable.2.

(Get String 2 –randomly generated) Generate a string with 5 randomly generated characters and save it in a variable.

(Calculate Distance) Compute the distance between the two strings and display it to the user

I think I have cracked the first one and part of the second but am having trouble saving string2 to a variable and I can't seem to wrap my head around calculating distance.

Any help would be appreciated.

This is what I have so far:

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

public class StringDiff {

    public static void main(String[] args) {
        
        Scanner scan = new Scanner(System.in);
        
        System.out.println ("Please enter 5 Capital letters.");
        int userString = scan.nextInt();
        
        Math.random().toString(255).substr(2, 5);           
    }
}



Aucun commentaire:

Enregistrer un commentaire