commit b4d8939e29f579ce0acc91410dbc3d552249b5c5 Author: Aelita4 Date: Tue Oct 18 09:04:44 2022 +0200 Lab2 part 1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -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 \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..0807c59 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..e4829ab --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + { + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.0", + "project.structure.side.proportion": "0.0", + "settings.editor.selected.configurable": "preferences.pluginManager" + } +} + + + + + + + + + 1666073128001 + + + + + + + \ No newline at end of file diff --git a/lab2.iml b/lab2.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/lab2.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..9bedbd8 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,133 @@ +import java.util.Locale; +import java.util.Random; +import java.util.Scanner; + +public class Main { + public static void z1() { + int n, a = 0, b = 10; + double suma = 0, pkt, ile = 0; + + Scanner scanner = new Scanner(System.in); + System.out.print("Podaj liczbę studentów: "); + n = scanner.nextInt(); + + if(n > 0) { + while(n > 0) { + System.out.print("Podaj ilość pkt (0-10):"); + pkt = scanner.nextDouble(); + + if(pkt >= a && pkt <= b) { + suma += pkt; + ile++; + n--; + } + } + + System.out.println("Ile: " + ile); + System.out.println("Suma: " + suma); + System.out.println("Średnia: " + (suma / ile)); + } else { + System.out.println("Ilość studentów musi być liczbą > 0"); + } + } + + public static double z2_wczytaj() { + Scanner scanner = new Scanner(System.in); + double a = scanner.nextDouble(); + return a; + } + + public static void z2() { + double sumaUjemne = 0, sumaDodatnie = 0, ileUjemnych = 0, n; + for(int i = 1; i <= 10; i++) { + System.out.print("Podaj " + i + " liczbę: "); + n = z2_wczytaj(); + + if(n < 0) { + sumaUjemne += n; + ileUjemnych++; + } else { + sumaDodatnie += n; + } + } + + System.out.println("Ujemnych: " + ileUjemnych); + System.out.println("Suma dodatnich: " + sumaDodatnie); + System.out.println("Suma ujemnych: " + sumaUjemne); + } + + public static void z3() { + Scanner scanner = new Scanner(System.in); + + int n; + System.out.print("Podaj n: "); + n = scanner.nextInt(); + + int x, sumaParzyste = 0; + for(int i = 1; i <= n; i++) { + System.out.print(i + ": "); + x = scanner.nextInt(); + + if(x % 2 == 0) { + sumaParzyste += x; + } + } + + System.out.println("Suma parzyste: " + sumaParzyste); + } + + public static void z4() { + Scanner scanner = new Scanner(System.in); + Random rand = new Random(); + + int a = -10, b = 45, x, sumaParzystych = 0; + + System.out.print("Podaj n: "); + int n = scanner.nextInt(); + + for(int i = 1; i <= n; i++) { + x = rand.nextInt(b - a + 1) + a; + System.out.println(i + ". " + x); + if(x % 2 == 0) { + sumaParzystych += x; + } + } + + System.out.println("Suma parzystych: " + sumaParzystych); + } + + public static void z5() { + String s; + Scanner scanner = new Scanner(System.in); + s = scanner.next(); + + s.toLowerCase(Locale.ROOT); + + boolean palindrom = true; + for(int i = 0; i < (s.length() / 2); i++) { + if(s.charAt(i) != s.charAt(s.length() - i - 1)) { + palindrom = false; + break; + } + } + + System.out.println(palindrom ? "Palindrom" : "Nie palindrom"); + } + + public static void main(String[] args) { + System.out.println("=== Zadanie 1 (grupa lab) ==="); + z1(); + + System.out.println("=== Zadanie 2 (10 liczb, suma) ==="); + z2(); + + System.out.println("=== Zadanie 3 (ciąg parzystych) ==="); + z3(); + + System.out.println("=== Zadanie 4 (losowanie, suma parzystych) ==="); + z4(); + + System.out.println("=== Zadanie 5 (palindrom) ==="); + z5(); + } +}