Last active
November 13, 2015 22:16
-
-
Save FreeFly19/ed9e22c6bdc74acdca70 to your computer and use it in GitHub Desktop.
Java Functions
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
public class Func1 { | |
public static void showArray (int[] a){ | |
for (int i = 0; i < a.length; i++) { | |
System.out.println(a[i]); | |
} | |
} | |
public static void main(String[] args) { | |
int[] arr = {3, 8, 213, 23, 34}; | |
showArray(arr); | |
} | |
} |
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
public class Func2 { | |
public static int sum (int a, int b){ | |
return a + b; | |
} | |
public static void main(String[] args) { | |
System.out.println(sum(3,5)); | |
int p = 4, q = 7; | |
int c = sum(p,q); | |
System.out.println(c); | |
} | |
} |
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
public class Func3 { | |
public static void fillFirstTwoElement (int[] a) { | |
a[0] = 5; | |
a[1] = 10; | |
} | |
public static void fillArrayNumbersOfElements (int[] array) { | |
for (int i = 0; i < array.length; i++) { | |
array[i] = i; | |
} | |
} | |
public static void printArray(int[] arr) { | |
for (int i = 0; i < arr.length; i++) { | |
if(i != arr.length-1) { | |
System.out.print(arr[i] + ", "); | |
} else { | |
System.out.print(arr[i]); | |
} | |
} | |
System.out.println(); | |
} | |
public static void main(String[] args) { | |
int[] a = new int[5]; | |
int[] b = new int[2]; | |
fillArrayNumbersOfElements(a); | |
printArray(a); | |
fillFirstTwoElement(a); | |
printArray(a); | |
b[1] = 13; | |
printArray(b); | |
fillFirstTwoElement(b); | |
printArray(b); | |
} | |
} |
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) { | |
Scanner sc = new Scanner(System.in); | |
String sign; | |
while(true) { | |
System.out.print("Input first number: "); | |
int first = sc.nextInt(); | |
System.out.print("Input second number: "); | |
int second = sc.nextInt(); | |
System.out.print("Input method (+,-,*,/): "); | |
sign = sc.next(); | |
switch (sign) { | |
case "*": | |
System.out.println("Result is " + (first * second)+"\n"); | |
continue; | |
case "+": | |
System.out.println("Result is " + (first + second)+"\n"); | |
continue; | |
case "-": | |
System.out.println("Result is " + (first - second)+"\n"); | |
continue; | |
case "/": | |
System.out.println("Result is " + (first / second)+"\n"); | |
continue; | |
default: | |
System.out.println("Invalid operation! Try again.\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
import java.util.Scanner; | |
public class Les1 { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Введите число: "); | |
int i = sc.nextInt(); | |
int k = 0, s = 0, q = 0; | |
while (k < i) | |
{ | |
if (q < s) | |
{ | |
k++; | |
System.out.print(k + " " + "\t"); | |
q++; | |
} | |
else | |
{ | |
System.out.println(); | |
q = 0; | |
s++; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment