Advertisement
DAIVOL

Code to change ln format (save as JapFormat.java)

Oct 19th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. /**
  8.  *
  9.  * @author DAIVOL
  10.  */
  11. import java.util.*;
  12. import java.io.*;
  13.  
  14.  
  15. public class JapFormat
  16. {
  17.  
  18.     public static void main(String[] args) throws IOException
  19. {
  20.     File file = new File("C:\\Users\\Daivol\\Documents\\NetBeansProjects\\jap\\test.txt"); // replace your txt file here, ONLY .txt FILE WORKS IN THIS
  21.     Scanner inputFile = new Scanner(file);
  22.     int k,i,j=0,x,y,l,m;
  23.    
  24.     ArrayList<char[]> chars = new ArrayList<>();
  25.          do {
  26.         chars.add(inputFile.nextLine().toCharArray());
  27.         }while (inputFile.hasNext());
  28.         char[][] line = chars.toArray(new char[chars.size()][]);     //takes input line by line
  29.         for(int a=1;a<line[0].length;a++)
  30.             line[0][a-1]=line[0][a];              // since for some reason the first line input starts from 1 instead of 0, idk why
  31.        
  32.      k=line.length;
  33.     /*for(i=0;i<k;i++)
  34.     { l=line[i].length;
  35.       m=i+1;
  36.          System.out.println("line "+m + " length is "+l);  // to see the length in different para
  37.         if(j<line[i].length)
  38.      {j=line[i].length;}    //to get biggest length,but seems redundant since it works only when all line have same length
  39.     }
  40.    
  41.     */
  42.  
  43.    for(x=0;x<k;x++)
  44.    {   for(y=0;y<line[x].length;y++)
  45.             System.out.print(line[x][y]);
  46.      l=line[x].length;
  47.       m=x+1;
  48.       System.out.println("  line "+m + " length is "+l);          // ALL LENGTH NEED TO BE SAME IN OUTPUT
  49.    
  50.    }
  51.    
  52.    
  53.     for(x=line[0].length-1;x>=0;--x)
  54.     {  for(i=0;i<k;i++)
  55.     { System.out.print(line[i][x]);
  56.     }
  57.      System.out.println();       // YOU MAY NEED TO SKIP FIRST AND SECOND LINE WHILE COPYING FROM OUTPUT
  58.     }
  59.    
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement