Advertisement
therrontelford

Label1

Jan 16th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.PrintWriter;
  3. import java.util.Scanner;
  4.  
  5. public class Labels {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9. /////////////////////This version does not have the fout statements.  You must add them beginning with substring(0,24)
  10.         Scanner kb = new Scanner(System.in);
  11.         Scanner fin=null; ////////
  12.         String input;
  13.         PrintWriter fout = null; ////////
  14.         String output;
  15.         String temp=null;  ////////
  16.         System.out.println("What is the name of the file?");
  17.         input = kb.nextLine();
  18.         System.out.println("What is the name of the output file?");
  19.         output = kb.nextLine();
  20.  
  21.         try {
  22.         fin = new Scanner(new File(input));
  23.         fout = new PrintWriter(new File(output));
  24.         }
  25.         catch (Exception e)
  26.         {
  27.             System.out.println("we have problems");
  28.         }
  29.  
  30.         while (fin.hasNextLine())
  31.         {
  32.             temp = fin.nextLine();
  33.  
  34.            
  35.                 System.out.print(temp.substring(0,24));
  36.                 System.out.println();
  37.            
  38.             if (temp.substring(44,45).equals(" "))  // assuming you left address2 blank
  39.             {
  40.            
  41.                 System.out.print(temp.substring(24,44));
  42.                 System.out.println();
  43.            
  44.             }
  45.             else    // assuming you had an address 1 and 2
  46.             {
  47.                
  48.                     System.out.print(temp.substring(24,44));
  49.                     System.out.println();
  50.                
  51.                
  52.                     System.out.print(temp.substring(44,64));
  53.                     System.out.println();
  54.                
  55.             }
  56.                
  57.                     System.out.print(temp.substring(64,84).trim()+ ", ");
  58.                    
  59.                
  60.                
  61.                     System.out.print(temp.substring(84,86) + "  ");
  62.            
  63.                
  64.                     System.out.print(temp.substring(86));
  65.                
  66.            
  67.                 System.out.println("\n");
  68.                
  69.            
  70.         }
  71.        
  72.        
  73.        
  74.        
  75.        
  76.  
  77.     }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement