-2
Myio is used by my teacher to replace scanner and etc the strings I’m going to use in the exercise are large and diverse so any example you think about is the basis. is my first post, I’m sorry if I stay out of the pattern!
import java.util.Random;
import java.util.*;
public class Aleatorio {
public static void alterarString(String in,char firstletra,char secundletra)
{
String out = in;
for(int i = 0;i < alterarString.length(); i++)
{
if(in.charAt(i) == firstletra)
{
out.charAt(i) == secundletra;
}
}
return out;
}
public static boolean theEnd(String s)
{
return (s.length() == 3 && s.charAt(0) == 'F' && s.charAt(1) == 'I' && s.charAt(2) == 'M');
}
public static void main(String[] args)
{
String[] frase = new String[1000];
int numString = 0;
do {
String[] frase[numString] = MyIo.nextLine();
}
while(theEnd(frase[numString++]) == false);
numString--;
Random gerador = new Random();
gerador . setSeed (4);
char secundletra;
char firstletra;
for(int i =0;i<numString; i++)
{
char firstletra = (char)('a'+(Math.abs( gerador.nextInt())%26)));
char secundletra = (char)('a'+(Math.abs( gerador.nextInt())%26)));
MyIo.println(alterarString (alterarString(frase[i],firstletra,secundletra)));
}
}
The variable alterrString within the function alterrString not declared. A typo?
– user201641
The right thing is java.util.Random import;, with a capital "R".
– Lucas Módolo
@Adrianosiqueira I didn’t even put,the variable I want in the function alterrString is String out,I would need to declare a variable with the same function name?
– Gabriel
I don’t know if I understand the purpose of the code, but maybe this will help: https://answall.com/a/449163/112052
– hkotsubo
@Gabriel, what exactly is this code supposed to do?
– user201641
-it has to take a string and draw two random minuscule letters for dps replace all occurrences of first letter in the string by the second and returns the string with the changes made @Adrianosiqueira
– Gabriel