Lab2 part 1
This commit is contained in:
		
						commit
						b4d8939e29
					
				| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="ProjectModuleManager">
 | 
			
		||||
    <modules>
 | 
			
		||||
      <module fileurl="file://$PROJECT_DIR$/lab2.iml" filepath="$PROJECT_DIR$/lab2.iml" />
 | 
			
		||||
    </modules>
 | 
			
		||||
  </component>
 | 
			
		||||
</project>
 | 
			
		||||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,78 @@
 | 
			
		|||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<project version="4">
 | 
			
		||||
  <component name="ChangeListManager">
 | 
			
		||||
    <list default="true" id="49638fa3-c946-4bb6-9c97-1a148c116245" 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$/lab2.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="FileTemplateManagerImpl">
 | 
			
		||||
    <option name="RECENT_TEMPLATES">
 | 
			
		||||
      <list>
 | 
			
		||||
        <option value="Class" />
 | 
			
		||||
      </list>
 | 
			
		||||
    </option>
 | 
			
		||||
  </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="2GIPSCMtHMWwcu8YkI6ihVwIoSe" />
 | 
			
		||||
  <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
 | 
			
		||||
  <component name="ProjectViewState">
 | 
			
		||||
    <option name="hideEmptyMiddlePackages" value="true" />
 | 
			
		||||
    <option name="showLibraryContents" value="true" />
 | 
			
		||||
  </component>
 | 
			
		||||
  <component name="PropertiesComponent">{
 | 
			
		||||
  "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"
 | 
			
		||||
  }
 | 
			
		||||
}</component>
 | 
			
		||||
  <component name="RunManager">
 | 
			
		||||
    <configuration name="Main" type="Application" factoryName="Application">
 | 
			
		||||
      <option name="MAIN_CLASS_NAME" value="Main" />
 | 
			
		||||
      <module name="lab2" />
 | 
			
		||||
      <method v="2">
 | 
			
		||||
        <option name="Make" enabled="true" />
 | 
			
		||||
      </method>
 | 
			
		||||
    </configuration>
 | 
			
		||||
  </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="49638fa3-c946-4bb6-9c97-1a148c116245" name="Changes" comment="" />
 | 
			
		||||
      <created>1666073128001</created>
 | 
			
		||||
      <option name="number" value="Default" />
 | 
			
		||||
      <option name="presentableId" value="Default" />
 | 
			
		||||
      <updated>1666073128001</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>
 | 
			
		||||
| 
						 | 
				
			
			@ -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>
 | 
			
		||||
| 
						 | 
				
			
			@ -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();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue