Forked from DenisZm/homework2_ArithmeticProgression.java
Last active
October 23, 2016 19:48
-
-
Save FreeFly19/6e320e730fff8ee887e1eac76d1efb70 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 homework2; | |
import java.util.Scanner; | |
/** | |
* Created by Denis on 18.10.2016. | |
*/ | |
public class ArithmeticProgression { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Input n: "); | |
int n = in.nextInt(); | |
System.out.println(n * (n + 1) /2); | |
} | |
} |
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 homework2; | |
import java.util.Scanner; | |
/** | |
* Created by Denis on 18.10.2016. | |
*/ | |
public class ArithmeticProgressionRecursion { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Input n: "); | |
int n = in.nextInt(); | |
ArithmeticProgressionRecursion ap = new ArithmeticProgressionRecursion(); | |
System.out.println(ap.sum(n)); | |
} | |
public int sum(int n){ | |
return n>1? n+sum(n-1): n; | |
} | |
} |
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 homework2; | |
/** | |
* Created by Denis on 18.10.2016. | |
*/ | |
public class BartSimpson { | |
public static void main(String[] args) { | |
BartSimpson bart = new BartSimpson(); | |
try { | |
int count = Integer.parseInt(args[0]); | |
bart.say(count); | |
} catch (NumberFormatException | IndexOutOfBoundsException ex) { | |
bart.usage(); | |
} | |
} | |
public void say(int c) { | |
for (int i = 0; i < c; i++){ | |
System.out.println("i will adopt best practices"); | |
} | |
} | |
public void usage() { | |
System.out.println("usage: BartSimpson count"); | |
System.out.println("\tcount: integer number"); | |
} | |
} |
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 homework2; | |
import java.util.Scanner; | |
/** | |
* Created by Denis on 18.10.2016. | |
*/ | |
public class DivisibleBy { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Input n: "); | |
int n = in.nextInt(); | |
System.out.print("Input m: "); | |
int m = in.nextInt(); | |
for (int i = 1; i <= n; i++) { | |
if ((i % m) == 0) 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 homework2; | |
/** | |
* Created by Denis on 18.10.2016. | |
*/ | |
public class MultiplicationTable { | |
public static void main(String[] args) { | |
for (int i = 1; i < 10; i++) { | |
for (int j = 1; j < 10; j++) { | |
System.out.printf("%4d", i*j); | |
} | |
System.out.println(); | |
} | |
} | |
} |
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 homework2; | |
/** | |
* Created by Denis on 18.10.2016. | |
*/ | |
public class MultiplicationTableHash { | |
public static void main(String[] args) { | |
for (int i = 1; i < 10; i++) { | |
for (int j = 1; j < 10; j++) { | |
if (i < j) { | |
System.out.printf("%4s", "#"); | |
} else { | |
System.out.printf("%4d", i*j); | |
} | |
} | |
System.out.println(); | |
} | |
} | |
} |
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 homework2; | |
/** | |
* Created by Denis on 18.10.2016. | |
*/ | |
public class NullToTwentyEvens { | |
public static void main(String[] args) { | |
for (int i = 0; i <= 20; i+=2) { | |
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 homework2; | |
/** | |
* Created by Denis on 18.10.2016. | |
*/ | |
public class OddEven { | |
public static void main(String[] args) { | |
int a = (int) (Math.random() * 100); | |
System.out.println(a); | |
if ((a % 2) == 0) { | |
System.out.println("even"); | |
} else { | |
System.out.println("odd"); | |
} | |
} | |
} |
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 homework2; | |
/** | |
* Created by Denis on 18.10.2016. | |
*/ | |
public class TenToNull { | |
public static void main(String[] args) { | |
int i = 10; | |
while (true) { | |
System.out.print(i--); | |
if (i < 0) break; | |
System.out.print(", "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment