Last active
December 11, 2016 21:56
-
-
Save Banafasto/1f4ab1008080e3644f0cce6926261d3a to your computer and use it in GitHub Desktop.
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
package com.gmail.kudr641; | |
import java.util.Scanner; | |
public class Example1Chapter3Level2 { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Input number:"); | |
int size = scanner.nextInt(); | |
scanner.close(); | |
String str = ""; | |
for (int i = 0; i < 2 * size - 1; i++) { | |
if (i < size) { | |
str += "*"; | |
} else { | |
str = str.substring(0, str.length() - 1); | |
} | |
System.out.println(str); | |
} | |
} | |
} |
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
package com.gmail.kudr641; | |
public class Example2Chapter3Level2 { | |
public static void main(String[] args) { | |
for (int i = 2; i <= 100; i += 1) { | |
boolean prime = true; | |
for (int j = i - 1; j > 1; j--) { | |
if (i % j == 0) { | |
prime = false; | |
} | |
} | |
if (prime == true) { | |
System.out.println(i); | |
} | |
} | |
} | |
} |
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
package com.gmail.kudr641; | |
import java.util.Scanner; | |
public class Example3Chapter3Level2 { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
System.out.println("Input size:"); | |
int size = scanner.nextInt(); | |
scanner.close(); | |
String str = ""; | |
if (size % 2 == 0) { | |
System.out.println("Number pair"); | |
} else { | |
for (int i = 0; i < size; i++) { | |
str += "*"; | |
} | |
for (int i = 0; i < size; i++) { | |
System.out.println(str); | |
if (i < size / 2) { | |
str = " " + str; | |
str = str.substring(0, str.length() - 2); | |
} | |
if (i >= size / 2) { | |
str += "**"; | |
str = str.substring(1, str.length()); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment