// 6. Um método que recebe um texto, uma posição e uma letra e substitui o caractere que esta na // posição pela letra recebida no parâmetro

// 6. Um método que recebe um texto, uma posição e uma letra e substitui o caractere que esta na
// posição pela letra recebida no parâmetro.

package exerciciosstring;

import java.util.Scanner;

public class EstudarA6 {
/*public static String analisar(String frase){
int posição;
String letra;

    for(int i=0; i<frase.length(); i++)
    {
    String lugar = frase.charAt(i)+ "";
    
    
    
    
    
      
      
    }
    String lugar;
    
    System.out.println(lugar); 
    
    return lugar;
}  */

public static void main(String[] args) {

    Scanner leitura = new Scanner(System.in);
    int L;
    String texto;
    String caracter;
    
          
    System.out.println("Digite o texto:");
    texto = leitura.nextLine();
    
    System.out.println("Digite a posição:");
    L = leitura.nextInt();
    
    System.out.println("Digite a letra:");
    caracter = leitura.nextLine();

    
    //if(L < texto.length())
    //for(int i=0; i<texto.length(); i++)
    if(L<texto.length())
    {
        String letra = texto.charAt(L)+ "";
       //texto = texto.replace(L ,caracter);
        
     
    }

// String retorno = analisar(texto);
//System.out.println(“Assim ficará com a troca:” + retorno);

    //String str.charAt(i);
    //System.out.println(ler);                
    //String s;
    //System.out.println(s); // antes

    //s = s.replace('1', 'c'); // troca o 1 pelo c : estou trocando a posicao 2 pois a contagem comeca do 0
                           // ou seja, 0 = a , 1 = b, 2 = 1 , 3 = d, 4 = e, 5 = f

//System.out.println(s); //depois
}
}
//String texto;
//char i;
//char letra;

   // System.out.println("Digite o texto:");
    //texto = leitura.nextLine();
    
   // System.out.println("Digite a posição que você deseja:");
    //i = (char) leitura.nextInt();
    
    //System.out.println("Digite a letra:");
    //letra = (char) leitura.nextInt();

JÁ TENTEI DE TUDO MAS NÃO CONSIGO FAZER DAR, O QUE PODE SER, OU FALTAR??

Isso quer dizer que o método recebe esses 3 parâmetros, ou seja:

static String troca(String original, int posicao, char letra) {
    char[] chars = original.toCharArray();
    chars[posicao] = letra;
    return new String(chars);
}

public static void main (String[] args) throws java.lang.Exception
{
    String s = "abcdef";
    System.out.println(troca(s, 2, 'x')); // abxdef	
}

Dentro do método, basta pegar o array de char da string, substituir a posição e criar a nova string.

Claro que você também pode colocar uma validação para garantir que a posição é válida, algo como:

if (posicao < 0 || posicao >= original.length())
    throw new IllegalArgumentException("posição inválida");