Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Cyfry {
- public static void main(String[] args)
- {
- String dane = "";
- try
- {
- dane = odczyt();
- }
- catch(Exception e)
- {
- //nie działa
- }
- String wynik = new String();
- int i=0;
- int a = Character.getNumericValue(dane.charAt(i));
- while(a!=-1)
- {
- wynik+=zamiana(a);
- i++;
- a = Character.getNumericValue(dane.charAt(i));
- }
- try
- {
- Zapis(wynik);
- }
- catch(Exception e)
- {
- //nie działa
- }
- }
- public static int zamiana(int x)
- {
- if(x==0)
- {
- return 9;
- }
- else
- {
- return x-1;
- }
- }
- public static String odczyt() throws FileNotFoundException, IOException {
- RandomAccessFile f = new RandomAccessFile("C:/users/Jacek/Desktop/cyfry.txt", "r");
- byte []bytes = new byte[255];
- f.read(bytes);
- String dane = new String(bytes);
- f.close();
- return dane;
- }
- public static void Zapis(String dane) throws FileNotFoundException, IOException
- {
- RandomAccessFile f = new RandomAccessFile("C:/users/Jacek/Desktop/cyfry_wynik.txt", "rw");
- byte []bytes = dane.getBytes();
- f.write(bytes);
- f.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement