Advertisement
Guest User

Untitled

a guest
Nov 28th, 2016
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.16 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5. import java.util.stream.Collector;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args) {
  10.         String imie = "Anna";
  11.         String nazwisko = new String("Kowalska");
  12.  
  13.         for (int i = 0; i < nazwisko.length() ; i+= 2) {
  14.             char literka = nazwisko.charAt(i); // imie[0];
  15.             System.out.print(literka);
  16.         }
  17.  
  18.         System.out.println();
  19.         String imie2 = new String("Anna");
  20.  
  21.         if (imie.equals(imie2)) {
  22.             System.out.println("Takie same");
  23.         } else {
  24.             System.out.println("Nie takie same");
  25.         }
  26.  
  27.         System.out.println(imie.compareTo(imie2));
  28.         System.out.println(imie.compareTo("Katarzyna"));
  29.         System.out.println("Katarzyna".compareTo(imie));
  30.  
  31.         int gdzie = nazwisko.indexOf("owal");
  32.         System.out.println("gdzie: " + gdzie);
  33.  
  34.         String zdanie = "Dziś jest piękny słoneczny poniedziałek";
  35.         String[] slowa = zdanie.split(" ");
  36.         System.out.println("Słowa:");
  37.  
  38.         for (String slowo : slowa) {
  39.             System.out.println(slowo);
  40.         }
  41.         for (int i = 0; i < slowa.length ; i++) {
  42.             System.out.println(slowa[i]);
  43.         }
  44.  
  45.         int liczba = 13;
  46.         String cyfry = "";
  47.         while(liczba > 0) {
  48.             int cyfra = liczba % 2;
  49.             cyfry = cyfra + cyfry;
  50.             liczba /= 2;
  51.         }
  52.         System.out.println("Binarnie: " + cyfry);
  53.  
  54.  
  55.         char znak = 'a' - 1;
  56.         int kod = znak;
  57.         System.out.println(znak);
  58.         System.out.println(kod);
  59.  
  60.         if (znak >= 'a' && znak <= 'z') {
  61.             // ....
  62.         }
  63.         if (Character.isLowerCase(znak)) {
  64.  
  65.         }
  66.  
  67.         kod = 98;
  68.         char znak2 = (char)kod;
  69.         System.out.println(znak2);
  70.  
  71.         int ile = '9' - '0';
  72.     }
  73.  
  74.     public static void zad1() {
  75.         Scanner in = new Scanner(System.in);
  76.  
  77.         int wynik = in.nextInt();
  78.         double suma = 0;
  79.         int ile = 0;
  80.         int dwoje = 0;
  81.         double maks = 2.0;
  82.  
  83.         while (wynik != -1) {
  84.             double ocena;
  85.             ++ile;
  86.  
  87.             if (wynik < 50) {
  88.                 ocena = 2.0;
  89.                 ++dwoje;
  90.             } else if (wynik < 60) {
  91.                 ocena = 3.0;
  92.             } else if (wynik < 70) {
  93.                 ocena = 3.5;
  94.             } else if (wynik < 80) {
  95.                 ocena = 4.0;
  96.             } else if (wynik < 90) {
  97.                 ocena = 4.5;
  98.             } else {
  99.                 ocena = 5.0;
  100.             }
  101.             suma += ocena;
  102.             if (ocena > maks) {
  103.                 maks = ocena;
  104.             }
  105.             wynik = in.nextInt();
  106.         }
  107.  
  108.         if (ile > 0) {
  109.             double srednia = suma / ile;
  110.             System.out.println("Średnia: " + srednia);
  111.  
  112.             if (srednia < 3.0 || dwoje > 1) {
  113.                 System.out.println("Zaliczenie: nie");
  114.             } else {
  115.                 System.out.println("Zaliczenie: tak");
  116.             }
  117.             System.out.println("Najwieksza: " + maks);
  118.         }
  119.     }
  120.  
  121.     public static void zad3() {
  122.         Random gen = new Random();
  123.  
  124.         int liczba = gen.nextInt(16 + 1) + 4;  // [4..20]
  125.         int suma = 0;
  126.  
  127.         for (int i = 1; i < liczba; i++) {
  128.             for (int j = 1; j < liczba; j++) {
  129.                 int n = i * j;
  130.  
  131.                 System.out.printf("%4d", n);
  132.  
  133.                 suma += n % 10;
  134.             }
  135.             System.out.println();
  136.         }
  137.         System.out.println("Suma cyfr: " + suma);
  138.     }
  139.  
  140.     public static void zad4() {
  141.         Random gen = new Random();
  142.         int liczba = gen.nextInt(150 + 1) + 50;  // [50..200]
  143.  
  144.         System.out.print("Liczba " + liczba + " w postaci binarnej (wspak) to: ");
  145.         int p = 1;
  146.         while (p * 2 <= liczba) {
  147.             p = p * 2;
  148.         }
  149.         while (p > 0) {
  150.             if (liczba >= p) {
  151.                 System.out.print(1);
  152.                 liczba = liczba - p;
  153.             } else {
  154.                 System.out.print(0);
  155.             }
  156.             p = p / 2;
  157.         }
  158.     }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement