add lab2
This commit is contained in:
parent
4417dfe95a
commit
ab62df0a7f
|
@ -1,58 +0,0 @@
|
|||
public class Lab1 {
|
||||
public static void main(String[] args) {
|
||||
// char c = 'a' + '1';
|
||||
char c = 97;
|
||||
// char c = '1';
|
||||
System.out.println(c);
|
||||
System.out.println((int) c);
|
||||
c++;
|
||||
System.out.println(c);
|
||||
System.out.println((int) c);
|
||||
System.out.println((double)'1'/'3');
|
||||
|
||||
// System.out.println( (double) 0 / 0 );
|
||||
// System.out.println( Math.sqrt(-1) );
|
||||
double s = 0;
|
||||
/*for (int i = 1; i <= 3; i++) { // 1) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> i = 1, 2) <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <= 3, 3) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 䳿 <EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
|
||||
System.out.println(i); // 4) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD> 1, 5) <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2
|
||||
// s = s + i;
|
||||
s += i;
|
||||
}*/
|
||||
/*int[] array = new int[2];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
|
||||
}*/
|
||||
final int A = -3;
|
||||
final int B = 0;
|
||||
final int N = 2;
|
||||
final int M = 2;
|
||||
|
||||
final int C = 1;
|
||||
// boolean wasDivisionByZero = false;
|
||||
// todo char
|
||||
// todo[clear code] think about avoiding brackets
|
||||
if ((A <= -C && -C <= N) || (B <= 0 && 0 <= M)) {
|
||||
System.out.println("Division by zero!");
|
||||
return;
|
||||
}
|
||||
/*myLabel:*/for (int i = A; i <= N /*&& !wasDivisionByZero*/; i++) {
|
||||
/*if (i + C == 0) { // todo optimize
|
||||
System.out.println("Division by zero!");
|
||||
wasDivisionByZero = true;
|
||||
break; //todo flag vs return;
|
||||
}*/
|
||||
for (int j = B; j <= M; j++) {
|
||||
/*if (j == 0) {
|
||||
System.out.println("Division by zero!");
|
||||
return;
|
||||
// wasDivisionByZero = true;
|
||||
// break myLabel;
|
||||
}*/
|
||||
s += (double) (i / j) / (i + C);
|
||||
}
|
||||
}
|
||||
// if (!wasDivisionByZero) {
|
||||
System.out.println("s = " + s);
|
||||
// }
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
public class Lab2 {
|
||||
public static void main(String[] args) {
|
||||
int[] array = {1, 2, 3};
|
||||
/*for (int i = 0; i < array.length; i++) {
|
||||
if (i % 2 == 0) {
|
||||
System.out.println("!" + array[i]);
|
||||
} else {
|
||||
System.out.println("?" + array[i]);
|
||||
}
|
||||
}*/
|
||||
|
||||
for (int i = 0; i < array.length; i+=2) {
|
||||
System.out.println("!" + array[i]);
|
||||
}
|
||||
|
||||
for (int i = 1; i < array.length; i+=2) {
|
||||
System.out.println("?" + array[i]);
|
||||
}
|
||||
|
||||
// зубчасті матриці
|
||||
int[][] matrix = {
|
||||
{1, 2},
|
||||
{3}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
public class lab2 {
|
||||
public static void main(String[] args){
|
||||
|
||||
// 2131 % 7 = 3; C7 = int
|
||||
|
||||
int[][] matrix = {
|
||||
{1,2,3,4,5},
|
||||
{1,3,5,7,9},
|
||||
{10,1,20,2,5}
|
||||
};
|
||||
|
||||
int rows = matrix.length;
|
||||
int column = matrix[0].length;
|
||||
System.out.println("Матриця:");
|
||||
for(int i = 0; i < rows; i++){
|
||||
for (int j = 0; j < column; j++){
|
||||
System.out.print(matrix[i][j]+" ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println();
|
||||
// 2131 % 5 = 1; C5 = транспортування;
|
||||
|
||||
int[][] transportMatrix = new int[column][rows];
|
||||
|
||||
|
||||
for(int i = 0; i < rows; i++){
|
||||
for(int j = 0; j < column; j++){
|
||||
transportMatrix[j][i] = matrix[i][j];
|
||||
}
|
||||
}
|
||||
System.out.println("Транспонована матриця:");
|
||||
for (int i = 0; i < column; i++){
|
||||
for (int j = 0; j < rows; j++){
|
||||
System.out.print(transportMatrix[i][j]+" ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
// 2131 % 11 = 8; C11 = Знайти середнє значення елементів кожного рядка матриці;
|
||||
int sum;
|
||||
for(int i = 0; i < rows; i++){
|
||||
sum = 0;
|
||||
for(int j = 0; j < column; j++){
|
||||
sum += matrix[i][j];
|
||||
}
|
||||
System.out.println("Середнє арифметичне " + (i+1) + " строки = " + (float)sum/column);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue