Aplicatie Java Cu Siruri (string)

  • Uploaded by: deianira
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Aplicatie Java Cu Siruri (string) as PDF for free.

More details

  • Words: 284
  • Pages: 2
// Aplicatie Java care lucreaza cu siruri si diverse metode din java.lang.String

//pt un sir dat,sa se efectueze operatiile: //verifica daca sirurile sunt egale;daca pointeaza spre aceeasi adresa de memorie; //creati un sir de stringuri //concatenare de siruri //crearea unui nou string cu op += //folosirea op de asociere de la stanga la dreapta + //folosirea metodelor toString();parseInt();parseLong();valueOf();floatValue(); //metoda equals,equalsIgnoreCase,compareTo(String altSir);

import java.lang.*; public class Siruri { public static void main (String[] args) { String sir1="a fost odata ca niciodata"; String sir2="ca daca nu ar fi fost,nu s-ar fi povestit"; //verifica daca sirurile sunt egale if (sir1.equals(sir2)) System.out.println("Sirurile sunt egale"); else System.out.println("Sirurile nu sunt egale"); //verifica daca sirurile pointeaza spre aceeasi adresa de memorie; if (sir1==sir2) System.out.println("sirurile pionteaza spre aceeasi adresa de memorie"); else System.out.println("sirurile nu pointeaza spre aceeasi adresa de memorie"); //concatenarea sirurilor sir1 si sir2 System.out.println("sirul 1 este:"+sir1); System.out.println("sirul 2 este:"+sir2); System.out.println("Concatenam sirurile:"+sir1+ " "+sir2);//am adaugat un spatiu pentru estetica //folosirea metodelor toString();parseInt();parseLong();valueOf();floatValue(); String sir_numere[]={"1","2","3","4","5","6","7","8","9" }; for (int i=0;i<sir_numere.length;i++) { System.out.println(sir_numere[i]);} String sir_nou=""; for (int i=0;i<sir_numere.length;i++) { sir_nou= sir_nou+sir_numere[i]; } System.out.println("stringul cu numere:"+sir_nou); //toString(); int a=-12365; System.out.println("a=("+a+")"); System.out.println("a transformat in sir:"+Integer.toString(a));

//parseInt() -converteste o val de tip String la Integer sau Long //declaram un sir String sir_pt_parse="-4563"; System.out.println("sirul convertit in int cu parseInt():" + Integer.parseInt(sir_pt_parse)); System.out.println("sirul convertit in int cu valueOf:" + Integer.valueOf(sir_pt_parse)); //metoda equalsIgnoreCase(); String sir3="A FOST ODATA CA NICIODATA"; if (sir1.equalsIgnoreCase(sir3)) System.out.println("OK"); else System.out.println("NU E OK"); //compareTo(); if (sir1.compareTo(sir3)==0) System.out.println("Sirurile sunt egale"); else System.out.println("Sirurile nu sunt egale"); //creati un sir de stringuri String[] sir_de_siruri=new String[3]; sir_de_siruri[0]="Ralph"; sir_de_siruri[1]="Waldo"; sir_de_siruri[2]="Emerson"; //concatenarea sirurilor din sir_de_siruri System.out.println(sir_de_siruri[0]+" "+sir_de_siruri[1]+" "+sir_de_siruri[2]); //crearea unui nou string cu op += String sir4=null; if (sir4==null) System.out.println("sirul e vid"); sir4+=sir_de_siruri[0]; System.out.println("sir4 este:"+sir4); sir4+=sir_de_siruri[1]; System.out.println("sir4 este:"+sir4); sir4+=sir_de_siruri[2]; System.out.println("sir4 este:"+sir4); } }

Related Documents


More Documents from ""

May 2020 18
Prefixoide
December 2019 12
Kirac-siyah Gece Lyrics
December 2019 17