This commit is contained in:
Aelita4 2022-10-25 08:47:58 +02:00
commit a1a89bd67c
Signed by: Aelita4
GPG Key ID: C217320B9C5FD53B
7 changed files with 287 additions and 0 deletions

29
.gitignore vendored Normal file
View File

@ -0,0 +1,29 @@
### IntelliJ IDEA ###
out/
!**/src/main/**/out/
!**/src/test/**/out/
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/lab3.iml" filepath="$PROJECT_DIR$/lab3.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

73
.idea/workspace.xml Normal file
View File

@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="168f23a3-085b-4647-87c8-c3685293d322" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/lab3.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2GcCEFm7xclAvhjPbItPZnbWBOY" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"settings.editor.selected.configurable": "preferences.pluginManager"
}
}]]></component>
<component name="RunManager">
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Main" />
<module name="lab3" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Main" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="168f23a3-085b-4647-87c8-c3685293d322" name="Changes" comment="" />
<created>1666678375462</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1666678375462</updated>
</task>
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
</component>
</project>

11
lab3.iml Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

154
src/Main.java Normal file
View File

@ -0,0 +1,154 @@
import java.util.Locale;
import java.util.Random;
import java.util.Scanner;
public class Main {
public static int[] z1_losowanie(int a, int b) {
Random rand = new Random();
int n = 10;
int[] tab = new int[n];
for(int i = 0; i < n; i++) {
tab[i] = rand.nextInt(b - a + 1) + a;
}
return tab;
}
public static void z1() {
int suma = 0;
double srednia;
int[] tab = z1_losowanie(10, 50);
for(int i = 0; i < tab.length; i++) {
suma += tab[i];
System.out.print(tab[i] + " ");
}
System.out.println();
System.out.println("Suma: " + suma);
System.out.println("Średnia: " + (suma / 10));
}
public static void z2() {
int[] parzystaIloscTab = {2, 3, 5, 7, 11, 13};
int[] nieparzystaIloscTab = {42, 69, 120, 240, 303};
for(int i = 0; i < parzystaIloscTab.length; i += 2) {
System.out.println("Parzysta: " + parzystaIloscTab[i]);
System.out.println("Nieparzysta: " + nieparzystaIloscTab[i]);
}
}
public static void z3() {
String[] tab = { "Stefan", "Andrzej", "Kamil" };
for(int i = 0; i < tab.length; i++) {
System.out.println(tab[i].toUpperCase(Locale.ROOT));
}
}
public static void z4() {
final int size = 5;
String[] tab = new String[size];
Scanner scanner = new Scanner(System.in);
for(int i = 0; i < size; i++) {
System.out.print("Podaj " + (i + 1) + " słowo: ");
tab[i] = scanner.next();
}
for(int i = (size - 1); i >= 0; i--) {
for(int j = (tab[i].length() - 1); j >= 0; j--) {
System.out.print(tab[i].charAt(j));
}
System.out.println();
}
}
public static void z5() {
int[] tab = { -15, -2, 0, 1, 10, 10, 20, 100 };
int tmp;
for(int i = 0; i < tab.length; i++) {
for(int j = 0; j < i; j++) {
if(tab[i] < tab[j]) {
tmp = tab[i];
tab[i] = tab[j];
tab[j] = tmp;
}
}
}
for(int i = 0; i < tab.length; i++) {
System.out.println((i + 1) + ". " + tab[i]);
}
}
public static long z6_silnia(int n) {
if(n == 0 || n == 1) return 1;
return n * z6_silnia(n - 1);
}
public static void z6() {
Scanner scanner = new Scanner(System.in);
final int size = 5;
int[] tab = new int[size];
long[] res = new long[size];
for(int i = 0; i < size; i++) {
System.out.print("Podaj " + (i + 1) + " liczbę: ");
tab[i] = scanner.nextInt();
res[i] = z6_silnia(tab[i]);
}
for(int i = 0; i < size; i++) {
System.out.println(tab[i] + "! = " + res[i]);
}
}
public static void z7() {
Scanner scanner = new Scanner(System.in);
final int size = 4;
String tab1[] = { "Stefan", "Andrzej", "Kamil", "Eustachy" };
String tab2[] = { "Stefan", "Andrzej", "Kamil", "Eustachy" };
for(int i = 0; i < size; i++) {
if(!tab1[i].equals(tab2[i])) {
System.out.println("Nie są równe na indeksie " + i);
return;
}
}
System.out.println("Są równe");
}
public static void main(String[] args) {
System.out.println("=== Zadanie 1 (suma i średnia) ===");
z1();
System.out.println("=== Zadanie 2 (co drugi) ===");
z2();
System.out.println("=== Zadanie 3 (duże litery) ===");
z3();
System.out.println("=== Zadanie 4 (wspak) ===");
z4();
System.out.println("=== Zadanie 5 (sortowanie) ===");
z5();
System.out.println("=== Zadanie 6 (silnia) ===");
z6();
System.out.println("=== Zadanie 7 (porównywanie) ===");
z7();
}
}