Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Testoo
- {
- private static Scanner keyboard;
- static int number = 0;
- public static void main(String[] args)
- {
- keyboard = new Scanner(System.in);
- while(true)
- {
- System.out.println("Enter the amouth of lines you want to your diamond: ");
- String d = keyboard.nextLine();
- if(Terve(d) == true)
- {
- number = Integer.parseInt(d);
- d= "";
- for(int x = 1; x <= number; x=x+2)
- {
- for (int y = 0; y < (number - x / 2); y++)
- System.out.print(" ");
- for (int y = 0; y < x; y++)
- System.out.print("*");
- System.out.println();
- }
- if (number%2==0)
- {
- for(int x = number-1; x > 0; x=x-2)
- {
- for (int y = 0; y < (number - x / 2); y++)
- System.out.print(" ");
- for (int y = 0; y < x; y++)
- System.out.print("*");
- System.out.println();
- }
- }
- else
- {
- for(int x = number-2; x > 0; x=x-2)
- {
- for (int y = 0; y < (number - x / 2); y++)
- System.out.print(" ");
- for (int y = 0; y < x; y++)
- System.out.print("*");
- System.out.println();
- }
- }
- }
- else if(d.length() == 0)
- {
- System.out.println("You entered nothing. Program will now terminate");
- break;
- }
- }
- }
- public static boolean Terve(String d)
- {
- try
- {
- Integer.parseInt(d);
- return true;
- } catch(NumberFormatException nfe)
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement