Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Kyle Scopa
- Write a program that requests an integer n and prints the following X picture.
- Sample run:
- Enter a positive integer: 5
- Output:
- X X
- X X
- X X
- X X
- X
- X X
- X X
- X X
- X X
- */
- import java.util.*;
- public class PrintX
- {
- public static void main(String args[])
- {
- int inp = 0;
- int inc = 0;
- int c = 0;
- Scanner input = new Scanner(System.in);
- inp = input.nextInt();
- //upper left..
- for (int i=1; i<inp; i++){
- for(int check= 1; check<i; check++){
- System.out.print(" ");
- }
- System.out.println("X");
- for (int l = (inp*2)-3-2*inc;l > 0;l--){
- System.out.print(" ");
- }
- System.out.printlx("x");
- inc++;
- }
- //middle x
- for (int p = 1; p <inp; p++){
- System.out.print(" ");
- }
- System.out.println("x");
- //lower left x
- for (int q = inp; q>1; q--){
- for(int check1 = 2; check1<q; check1++){
- System.out.print(" ");
- }
- System.out.println("x");
- }
- }
- }
Add Comment
Please, Sign In to add comment