Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. package Exercicio1;
  2.  
  3. import java.io.BufferedWriter;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileWriter;
  7. import java.io.IOException;
  8. import java.util.Scanner;
  9.  
  10. public class Transforma_Telefone {
  11. public static void main (String[] args) throws IOException, FileNotFoundException{
  12.  
  13. String telefones = "C:/Users/renat/Desktop/Telefones.txt";
  14. File texto = new File(telefones);
  15. Scanner lendo = new Scanner(texto);
  16. File listaNova = new File("C:/Users/renat/Desktop/Telefones_Novos.txt");
  17. BufferedWriter escrevendo = new BufferedWriter(new FileWriter(listaNova));
  18.  
  19. while(lendo.hasNextLine()){
  20. String linha = lendo.nextLine();
  21. String[] linhaNova = new String[30];
  22. for(int i=0;i<linha.length();i++){
  23. char digito = linha.charAt(i);
  24. switch (digito) {
  25. case '1':
  26. case '0':
  27. case '-':
  28. linhaNova[i]= String.valueOf(digito);
  29. break;
  30. case 'A':
  31. case 'B':
  32. case 'C':
  33. linhaNova[i]= "2";
  34. break;
  35. case 'D':
  36. case 'F':
  37. case 'E':
  38. linhaNova[i]= "3";
  39. break;
  40. case 'G':
  41. case 'H':
  42. case 'I':
  43. linhaNova[i]= "4";
  44. break;
  45. case 'J':
  46. case 'K':
  47. case 'L':
  48. linhaNova[i]= "5";
  49. break;
  50. case 'M':
  51. case 'N':
  52. case 'O':
  53. linhaNova[i]= "6";
  54. break;
  55. case 'P':
  56. case 'Q':
  57. case 'R':
  58. case 'S':
  59. linhaNova[i]= "7";
  60. break;
  61. case 'T':
  62. case 'U':
  63. case 'V':
  64. linhaNova[i]= "8";
  65. break;
  66. case 'W':
  67. case 'X':
  68. case 'Y':
  69. case 'Z':
  70. linhaNova[i]= "9";
  71. break;
  72. }
  73. }
  74. for(int j=0;j<linha.length();j++){
  75. System.out.print(linhaNova[j]);
  76. escrevendo.write(linhaNova[j]);
  77. int l =j+1;
  78. if(l==linha.length()){
  79. System.out.println();
  80. escrevendo.newLine();
  81. }
  82. }
  83. }
  84. escrevendo.close();
  85. lendo.close();
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement