Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication1;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author richard
- */
- public class JavaApplication1 {
- /**
- * @param args the command line arguments
- */
- private static String readFileAsString(String filePath) throws java.io.IOException{
- byte[] buffer = new byte[(int) new File(filePath).length()];
- FileInputStream f = new FileInputStream(filePath);
- f.read(buffer);
- return new String(buffer);
- }
- public static void main(String[] args) {
- try {
- // TODO code application logic here
- String file = readFileAsString("C:\\Test.txt");
- String[] arr = file.split("#");
- int i = 0;
- for(String zeile:arr){
- i++;
- System.out.printf("Zeile %d: %s\n",i,zeile);
- }
- //Zufällige Zeile bestimmen
- int zeile = (int)((arr.length)*Math.random());
- System.out.printf("\n\nZufällige Zeile Nummer: %d\n%s",zeile,arr[zeile]);
- String deineZeile = arr[zeile];
- char[] zeichen = deineZeile.toCharArray();
- int tauschA = (int)((zeichen.length)*Math.random());
- int tauschB = (int)((zeichen.length)*Math.random());
- char buff = zeichen[tauschA];
- zeichen[tauschA] = zeichen[tauschB];
- zeichen[tauschB] = buff;
- System.out.printf("\n\nVertausche Zeichen %d mit Zeichen %d: \n%s",tauschA,tauschB, new String(zeichen));
- } catch (IOException ex) {
- Logger.getLogger(JavaApplication1.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
Add Comment
Please, Sign In to add comment