Advertisement
colonel-top

NewExam java Try 1st Time

Jun 25th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.03 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6. import java.io.BufferedReader;
  7. import java.util.Scanner;
  8. public class NewExam
  9. {
  10.     static String txtw="";
  11.     public static void main (String[] args)
  12.     {
  13.        
  14.         String input ="";
  15.         //String input = new Scanner(System.in).nextLine();
  16.         String path = "D:\\Study\\Java\\NewMain\\src\\input.txt";
  17.         File file = new File(path);
  18.         try
  19.         {
  20.             BufferedReader br = new BufferedReader (new FileReader(file));
  21.             String line="";
  22.             while ((line = br.readLine()) != null)
  23.             {
  24.                 input = line;
  25.                
  26.                 check(input);
  27.             }
  28.            
  29.             br.close();
  30.         }
  31.         catch(IOException e)
  32.         {
  33.             e.printStackTrace();
  34.         }
  35.     }
  36.     static void check (String inputname)
  37.     {
  38.        
  39.         char[] lower = "abcdefghijklmnopqrstuvwxyz" .toCharArray();
  40.         char[] higher = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" .toCharArray();
  41.         char[] lowerdecode = "ZYXWVUTSRQPONMLKJIHGFEDCBA" .toCharArray();
  42.         char[] higherdecode = "zyxwvutsrqponmlkjihgfedcba" .toCharArray();
  43.         String sumtext="";
  44.         int inputlong = inputname.length();
  45.         char[] cinput = inputname.toCharArray();
  46.         for (int a=0;a<inputlong;a++)
  47.         {
  48.             if(Character.isLetter(cinput[a]))
  49.             {
  50.                
  51.                 for (int i = 0 ; i < 26 ; i++)
  52.                 {
  53.                     if(cinput[a] == lower[i])
  54.                     {
  55.                         String tmp = Character.toString(lowerdecode[i]);
  56.                         sumtext += tmp;
  57.                     }
  58.                     else if (cinput[a] == higher[i])
  59.                     {
  60.                         String tmp2 = Character.toString(higherdecode[i]);
  61.                         sumtext += tmp2;
  62.                     }
  63.                 }
  64.             }
  65.             else
  66.             {
  67.                 String tmp3 = Character.toString(cinput[a]);
  68.                 sumtext += tmp3;
  69.             }
  70.                
  71.         }
  72.        
  73.         txtw = sumtext+"\n";
  74.         System.out.print(txtw);
  75.         writefile();
  76.     }
  77.     static void writefile ()
  78.     {
  79.         try
  80.         {
  81.             FileWriter writer = new FileWriter("D:\\Study\\Java\\NewMain\\src\\output.txt",true);
  82.             writer.write(txtw);
  83.              writer.write(System.getProperty( "line.separator" ));
  84.             writer.close();
  85.         }
  86.         catch (IOException e)
  87.         {
  88.             e.printStackTrace();
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement