Created
January 4, 2018 18:30
-
-
Save dengsauve/b2cc038852d9b7dccfe0a09d19468280 to your computer and use it in GitHub Desktop.
Java Class Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
int counter = 1; | |
while(counter<5){ | |
System.out.println("Hello World!"); | |
System.out.println("Hello Dennis!"); | |
counter++; | |
} | |
for(int i=0; i<5; i++){ | |
System.out.println("Counter: " + i); | |
} | |
Scanner input = new Scanner(System.in); | |
System.out.print("Please enter a side length: "); | |
int size = input.nextInt(); | |
//System.out.println(DrawBox(size)); | |
System.out.println(DrawTriangle(size)); | |
} | |
public static String DrawBox( int sideLength ){ | |
String returnString = ""; | |
// Top of Box | |
returnString += RepeatString(sideLength, "*"); | |
returnString += "\n"; | |
//printing the sides | |
for(int i=1; i<sideLength; i++){ | |
returnString += "*"; | |
returnString += RepeatString(sideLength - 2, " "); | |
returnString += "*\n"; | |
} | |
// Bottom of Box | |
returnString += RepeatString(sideLength, "*"); | |
return returnString; | |
} | |
public static String DrawTriangle(int sideLenth){ | |
String returnString = ""; | |
//top | |
returnString += "*\n"; | |
//body | |
for(int i=0; i<sideLenth-2; i++){ | |
returnString += "*"; | |
returnString += RepeatString(i, " "); | |
returnString += "*\n"; | |
} | |
returnString += RepeatString(sideLenth, "*"); | |
return returnString; | |
} | |
public static String RepeatString(int times, String ch){ | |
String returnString = ""; | |
for(int i=0; i<times; i++){ | |
returnString += ch; | |
} | |
return returnString; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment