Advertisement
hexwolfman

Challenge 20 I/O

Jul 23rd, 2019
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. //Hector Villalobos
  2. //PROGRAMMING I M-F 11am
  3.  
  4. import java.util.Scanner;
  5. import java.io.*;
  6.  
  7. public class Challenge20SquareDisplayOutput {
  8.   public static void main(String[] args) throws IOException {
  9.    
  10.     Scanner keyboard = new Scanner(System.in);
  11.    
  12.     PrintWriter outputFile = new PrintWriter("SquareDisplay.txt");
  13.    
  14.     System.out.print("Enter a positive integer no greater than 15: ");
  15.     int input = keyboard.nextInt();
  16.    
  17.     while(input > 15) {
  18.       System.out.print("Invalid integer. Try Again: ");
  19.       input = keyboard.nextInt();
  20.     }
  21.    
  22.     for(int i = 1; i <= input; i++) {
  23.       for(int j = 1; j <= input; j++)
  24.         outputFile.print("X");
  25.       outputFile.println();      
  26.     }
  27.     outputFile.close();
  28.     System.out.println("Data written to the file.");
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement