Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- import java.util.Arrays;
- import java.util.Scanner;
- public class Edytor {
- String[] content;
- public Edytor() {
- content = new String[1];
- }
- public void run() {
- int m;
- Scanner read = new Scanner(System.in);
- while (true) {
- System.out.println("1. Dodaj linie.");
- System.out.println("2. Usuń linie.");
- System.out.println("3. Dodaj tekst na końcu wybranej linii.");
- System.out.println("4. Pokaż wszystko.");
- System.out.println("0. Wyjdź.");
- m = read.nextInt();
- if (m > 0 && m < 4) {
- System.out.println("Podaj numer linii:");
- int number = read.nextInt();
- switch (m) {
- case 1: {
- Scanner newLine = new Scanner(System.in);
- System.out.println("Podaj tekst:");
- String line = newLine.nextLine();
- checkLength(number);
- content[number - 1] = line;
- break;
- }
- case 2: {
- if (number == content.length)
- content = (String[]) Arrays.copyOf(content, number - 1);
- if (number < content.length)
- content[number] = "";
- break;
- }
- case 3: {
- if (content.length < number)
- break;
- Scanner newLine = new Scanner(System.in);
- System.out.println("Podaj tekst:");
- String line = newLine.nextLine();
- checkLength(number);
- content[number - 1] = content[number - 1].concat(line);
- break;
- }
- }
- } else if (m == 4) {
- for (int i = 0; i < content.length; i++)
- if (content[i] == null)
- System.out.println("");
- else
- System.out.println(content[i]);
- }
- else if (m == 0) {
- read.close();
- break;
- }
- }
- }
- public void checkLength(int number) {
- if (number > content.length)
- content = (String[]) Arrays.copyOf(content, number);
- }
- public static void main(String[] args) {
- Edytor editor = new Edytor();
- editor.run();
- }
- }
- */
- /*
- package zad2;
- import java.util.Arrays;
- public class Stos {
- int[] stack = null;
- public void push(int newInt){
- if(stack == null)
- stack = new int[1];
- else
- stack = Arrays.copyOf(stack, stack.length + 1);
- stack[stack.length-1] = newInt;
- }
- public int pop(){
- int ret = stack[stack.length-1];
- stack = Arrays.copyOf(stack, stack.length - 1);
- return ret;
- }
- public void showStack(){
- for(int i=stack.length-1;i >= 0; i--)
- System.out.println(stack[i]);
- System.out.println();
- }
- public static void main(String[] args){
- Stos stack = new Stos();
- stack.push(2);
- stack.push(5);
- stack.push(3);
- stack.showStack();
- stack.pop();
- stack.push(12);
- stack.showStack();
- }
- }
- */
- /*
- import java.util.Arrays;
- class Grupa {
- String nazwa;
- Student[] studenci;
- public Grupa(String nazwa){
- this.nazwa = nazwa;
- studenci = null;
- }
- public void dodajStudenta(Student student) {
- if (studenci == null)
- studenci = new Student[1];
- else
- studenci = (Student[]) Arrays.copyOf(studenci, studenci.length + 1);
- studenci[studenci.length - 1] = student;
- Arrays.sort(studenci);
- }
- public void usunStudenta(int ind){
- studenci[ind] = studenci[studenci.length-1];
- studenci = (Student[]) Arrays.copyOf(studenci, studenci.length - 1);
- Arrays.sort(studenci);
- }
- public void sklad(){
- System.out.println(this.nazwa);
- for(int i = 0;i < studenci.length;i++){
- System.out.println(studenci[i]);
- }
- }
- }
- @SuppressWarnings("rawtypes")
- class Student implements Comparable {
- String imie;
- String nazwisko;
- Grupa grupa;
- public Student(String imie, String nazwisko, Grupa grupa) {
- this.imie = imie;
- this.nazwisko = nazwisko;
- this.grupa = grupa;
- }
- @Override
- public String toString(){
- return imie + " " + nazwisko;
- }
- @Override
- public int compareTo(Object o) {
- Student p = (Student) o;
- int porownaneNazwiska = nazwisko.compareTo(p.nazwisko);
- if (porownaneNazwiska == 0) {
- return imie.compareTo(p.imie);
- } else {
- return porownaneNazwiska;
- }
- }
- }
- public class Dziekanat {
- public static void main(String[] args){
- Grupa g1 = new Grupa("2ID12");
- g1.dodajStudenta(new Student("Jan","Kowalski",g1));
- g1.dodajStudenta(new Student("Andrzej","Kowalski",g1));
- g1.dodajStudenta(new Student("Jan","Adamczyk",g1));
- g1.dodajStudenta(new Student("Jan","Ziemczyk",g1));
- g1.sklad();
- int x = Arrays.binarySearch(g1.studenci, new Student("Jan","Kowalski",g1));
- System.out.println(x);
- g1.usunStudenta(x);
- g1.sklad();
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement