Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public class Cyfry {
  2. public static void main(String[] args)
  3. {
  4. String dane = "";
  5. try
  6. {
  7. dane = odczyt();
  8. }
  9. catch(Exception e)
  10. {
  11. //nie działa
  12. }
  13.  
  14. String wynik = new String();
  15. int i=0;
  16. int a = Character.getNumericValue(dane.charAt(i));
  17. while(a!=-1)
  18. {
  19. wynik+=zamiana(a);
  20. i++;
  21. a = Character.getNumericValue(dane.charAt(i));
  22. }
  23.  
  24. try
  25. {
  26. Zapis(wynik);
  27. }
  28. catch(Exception e)
  29. {
  30. //nie działa
  31. }
  32.  
  33.  
  34.  
  35. }
  36. public static int zamiana(int x)
  37. {
  38. if(x==0)
  39. {
  40. return 9;
  41. }
  42. else
  43. {
  44. return x-1;
  45. }
  46. }
  47. public static String odczyt() throws FileNotFoundException, IOException {
  48.  
  49. RandomAccessFile f = new RandomAccessFile("C:/users/Jacek/Desktop/cyfry.txt", "r");
  50. byte []bytes = new byte[255];
  51. f.read(bytes);
  52. String dane = new String(bytes);
  53. f.close();
  54. return dane;
  55. }
  56.  
  57. public static void Zapis(String dane) throws FileNotFoundException, IOException
  58. {
  59. RandomAccessFile f = new RandomAccessFile("C:/users/Jacek/Desktop/cyfry_wynik.txt", "rw");
  60. byte []bytes = dane.getBytes();
  61. f.write(bytes);
  62. f.close();
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement