Informática, perguntado por xremix20, 11 meses atrás

boas pessoal estou com uma dúvida precisava de saber com alguma urgência como posso fazer esta função sem nenhuma instrução ou ciclos porque vou ter amanha exame.
o código que fiz foi este:
static Scanner teclado = new Scanner (System.in);
public static char letra(byte i){

int pos =0;
char alfabeto[]={'a','b','c','d','e','f','g','h','i','j','l','m','n','o','p','q','r','s','t','u','v','x','z','y','w','k'};
int numb[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26};
alfabeto = teclado.next().indexOf(numb[i]);
return 0;
}
public static void main(String[] args) {
letra(i);
}
}

Anexos:

Soluções para a tarefa

Respondido por bokomoko
0
você complicou muito

Tente assim

import java.util.Scanner;

class Main {
   public static char letra(byte i){
        char alfabeto[]=
{'a','b','c','d','e','f','g','h','i','j','l','m','n','o','p','q','r','s','t','u','v','x','z','y','w','k'};
      return alfabeto[i-1]; 
    }
     public static void main(String[] args) {
    Scanner teclado = new Scanner (System.in);
    byte wi = 0;
    System.out.print("Informe um número de 1 a 26");
    wi = teclado.nextByte();
    System.out.print("Digitou "+wi+" e a letra correspondente é ");
    System.out.println( letra(wi) );
  }
}


dá uma olhada nele aqui rodando
https://repl.it/@bokomoko/letra-por-codigo


Perguntas interessantes