-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ca144a
commit 3c2e35c
Showing
24 changed files
with
1,810 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package labs.lab1; | ||
|
||
import java.util.Scanner; | ||
|
||
/** | ||
* Created by User on 09.04.2017. | ||
*/ | ||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner scanner=new Scanner(System.in); | ||
short n=0; | ||
System.out.printf("n="); | ||
if (scanner.hasNextShort()){ | ||
n=scanner.nextShort(); | ||
} | ||
short m=0; | ||
System.out.printf("m="); | ||
if (scanner.hasNextShort()){ | ||
m=scanner.nextShort(); | ||
} | ||
float S=0f; | ||
short C=0; | ||
for (short i=0; i<=n; i++){ | ||
for (short j=0; j<=m; j++){ | ||
if (i-C!=0){ | ||
S+=(float)(i+j)/(float)(i-C); | ||
} | ||
} | ||
} | ||
System.out.println("Sum="+S); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package labs.lab2; | ||
/** | ||
* Created by User on 09.04.2017. | ||
*/ | ||
|
||
/** | ||
* operation - direct sum | ||
* type of elements - byte | ||
* operation with C - find average value of each row of matrix | ||
*/ | ||
|
||
import java.util.Scanner; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
Scanner scanner = new Scanner(System.in); | ||
//Input matrix A | ||
int n = 0; | ||
System.out.printf("Size of A[n x n]: "); | ||
if (scanner.hasNextInt()) { | ||
n = scanner.nextInt(); | ||
} | ||
System.out.printf("Input elements of A:\n"); | ||
byte[][] A = new byte[n][n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < n; j++) { | ||
if (scanner.hasNextByte()) { | ||
A[i][j] = scanner.nextByte(); | ||
} | ||
} | ||
} | ||
//Input matrix B | ||
int m = 0; | ||
System.out.printf("Size of B[m x m]: "); | ||
if (scanner.hasNextInt()) { | ||
m = scanner.nextInt(); | ||
} | ||
System.out.printf("Input elements of B:\n"); | ||
byte[][] B = new byte[m][m]; | ||
|
||
for (int i = 0; i < m; i++) { | ||
for (int j = 0; j < m; j++) { | ||
if (scanner.hasNextByte()) { | ||
B[i][j] = scanner.nextByte(); | ||
} | ||
} | ||
} | ||
|
||
//Calculate matrix | ||
int k=n+m; | ||
byte [][] C=new byte[k][k]; | ||
for (int i=0; i<k; i++){ | ||
for (int j=0; j<k; j++){ | ||
if (i<n){ | ||
if (j<n){ | ||
C[i][j]=A[i][j]; | ||
} else{ | ||
C[i][j]=0; | ||
} | ||
} else{ | ||
if (j>=n){ | ||
C[i][j]=B[i-n][j-n]; | ||
} else { | ||
C[i][j] = 0; | ||
} | ||
} | ||
} | ||
} | ||
//Output matrix C | ||
System.out.printf("Matrix C:\n"); | ||
for(int i=0; i<k; i++){ | ||
for (int j=0; j<k; j++){ | ||
System.out.printf("%4d", C[i][j]); | ||
} | ||
System.out.printf("\n"); | ||
} | ||
|
||
//Calculate average value fot each row | ||
float sum; | ||
for (int i=0; i<k; i++){ | ||
sum=0; | ||
for (int j=0; j<k; j++){ | ||
sum+=C[i][j]; | ||
} | ||
System.out.printf("Row %d Average %.2f\n", i, (float)(sum/k)); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package labs.lab3; | ||
|
||
/** | ||
* Created by User on 09.04.2017. | ||
*/ | ||
public class Main { | ||
public static void main(String[] args) { | ||
StringBuilder text = new StringBuilder("Some text. Some more text. And a little more text."); | ||
StringBuilder sentence; | ||
StringBuilder newtext = new StringBuilder(""); | ||
StringBuilder word1; | ||
StringBuilder word2; | ||
int next = text.indexOf("."); | ||
int prev = -1; | ||
while (next != -1) { | ||
sentence = new StringBuilder(text.subSequence(prev + 1, next)); | ||
if (sentence.charAt(0) == ' ') { | ||
sentence = new StringBuilder(sentence.substring(1)); | ||
} | ||
word1 = new StringBuilder(sentence.substring(0, sentence.indexOf(" "))); | ||
word2 = new StringBuilder(sentence.substring(sentence.lastIndexOf(" ") + 1, sentence.length())); | ||
word2.replace(0, 1, word2.substring(0, 1).toUpperCase()); | ||
sentence.replace(0, sentence.indexOf(" "), word2.toString()); | ||
sentence.replace(sentence.lastIndexOf(" "), sentence.length(), " " + word1.toString()); | ||
newtext.append(sentence); | ||
newtext.append(". "); | ||
prev = next; | ||
next = text.indexOf(".", next + 1); | ||
} | ||
System.out.println(text); | ||
System.out.println(newtext); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package labs.lab4; | ||
|
||
/** | ||
* Created by User on 30.04.2017. | ||
*/ | ||
public abstract class Char { | ||
protected char ch; | ||
|
||
abstract void print(); | ||
|
||
/** | ||
* Перевіряє, чи є символ кінцем речення | ||
*/ | ||
boolean isEndOfSentence() { | ||
return false; | ||
} | ||
|
||
/** | ||
* Перевіряє, чи є символ пробілом | ||
*/ | ||
static boolean isWhitespace(char ch) { | ||
return Character.isWhitespace(ch); | ||
} | ||
|
||
/** | ||
* Перевіряє, чи є символ частиною слова | ||
*/ | ||
static boolean isLetterOrDigit(char ch) { | ||
return Character.isLetterOrDigit(ch); | ||
} | ||
|
||
/** | ||
* Перевіряє, чи є символ знаком пунктуації | ||
*/ | ||
static boolean isPunctuation(char ch) { | ||
if (".,?!;:".indexOf(ch) != -1) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package labs.lab4; | ||
|
||
/** | ||
* Created by User on 30.04.2017. | ||
*/ | ||
public class Letter extends Char { | ||
|
||
Letter(){ | ||
ch=0; | ||
} | ||
|
||
Letter(char ch){ | ||
this.ch=ch; | ||
} | ||
|
||
@Override | ||
public void print() { | ||
System.out.print(ch); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package labs.lab4; | ||
|
||
/** | ||
* Created by User on 29.04.2017. | ||
*/ | ||
public class Main { | ||
public static void main(String[] args) { | ||
String s = new String("Some, text. Some more; text? And a little: more text!.."); | ||
/** | ||
* Створюєм ієрархію | ||
*/ | ||
Text text = new Text(s); | ||
/** | ||
* Завдання по варіанту | ||
*/ | ||
text.swap(); | ||
text.print(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package labs.lab4; | ||
|
||
/** | ||
* Created by User on 03.05.2017. | ||
*/ | ||
public class Punctuation extends Char { | ||
/** | ||
* Номер слова, після якого в реченні ставиться даний знак | ||
*/ | ||
int seqNumber; | ||
|
||
Punctuation(char ch, int n) { | ||
this.ch = ch; | ||
seqNumber = n; | ||
} | ||
|
||
Punctuation(char ch) { | ||
this.ch = ch; | ||
} | ||
|
||
public boolean isEndOfSentence() { | ||
if (this != null && (ch == '.' || ch == '!' || ch == '?')) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Повертає номер слова, після якого в реченні ставиться даний знак | ||
*/ | ||
public int getSeqNumber() { | ||
return seqNumber; | ||
} | ||
|
||
public void print() { | ||
System.out.print(ch); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package labs.lab4; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Created by User on 30.04.2017. | ||
*/ | ||
public class Sentence { | ||
private ArrayList<Word> words; | ||
private ArrayList<Punctuation> punctuations; | ||
|
||
Sentence() { | ||
words = new ArrayList<>(); | ||
punctuations = new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Додає слово в речення | ||
*/ | ||
public void addWord(Word w) { | ||
words.add(w); | ||
} | ||
|
||
/** | ||
* Додає знак пунктуації в речення | ||
*/ | ||
public void addPunctuation(char ch) { | ||
punctuations.add(new Punctuation(ch, words.size() - 1)); | ||
|
||
} | ||
|
||
public void print() { | ||
int j = 0; | ||
for (int i = 0; i < words.size(); i++) { | ||
words.get(i).print(); | ||
while (j < punctuations.size() && punctuations.get(j).getSeqNumber() == i) { | ||
punctuations.get(j).print(); | ||
j++; | ||
} | ||
System.out.print(' '); | ||
} | ||
} | ||
|
||
/** | ||
* Міняє місцями перше і останнє слово в реченні | ||
*/ | ||
public void swap() { | ||
Collections.swap(words, 0, words.size() - 1); | ||
} | ||
} |
Oops, something went wrong.