tema 2 programare

Upload: silai-gaby

Post on 03-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 TEMA 2 Programare

    1/6

    Problema 1

    import java.util.Scanner;publicclass Problema1_L1 {

    publicstaticvoid main(String[] args) {

    String word = "Aplicatie text. Stabiliare compozitie text.";char[] stringArray;int propozitie=0;

    int cuvant=0;int procente=0;char[] tablou=word.toCharArray();

    int litere = word.length(); //conversie numarul de caractere dinsirul de numere

    char alfabet[]={'a','b','c','d','e','f'};System.out.println("Numarul de litere in fraza :"+"\t"+litere);

    for(int i=0;i

  • 7/29/2019 TEMA 2 Programare

    2/6

    Problema 2

    class CompletareaSirurilor {publicstaticvoid main(String[] args) {

    // declares an array of integersint[] anArray;

    // allocates memory for 10 integersanArray = newint[10];

    // initialize first elementanArray[0] = 100;// initialize second elementanArray[1] = 200;// etc.anArray[2] = 300;anArray[3] = 400;anArray[4] = 500;anArray[5] = 600;

    anArray[6] = 700;anArray[7] = 800;anArray[8] = 900;anArray[9] = 1000;for(int i=0;i

  • 7/29/2019 TEMA 2 Programare

    3/6

    Problema 4.

    publicclass CompletareVocale {

    publicstaticvoid main(String[] args) {

    String propozitie = "Aplicatie text. Stabiliarecompozitie text.";

    char vocale []={'a','e','i','o','u'};char[] tablou=propozitie.toCharArray();char[] CodareFinal;

    char[] tablouProp = propozitie.toCharArray();

    for(int i=0;i

  • 7/29/2019 TEMA 2 Programare

    4/6

    }}System.out.println(originalString);System.out.println(s);

    }}

    Problema ///combinatii de criprografie generare de numere :P

    Java has a class called java.util.Random which can generate random numbers. If youwant something to happen with probability 1/25, simply generate a random number

    between 1 and 25 (or 0 and 24 inclusive) and check whether that number is equal to

    1.

    if(new java.util.Random().nextInt(25)==0){

    //Do something.

    }

    Problema inlocuire vocale CORECT!!!

    publicclass CompletareVocale {publicstaticvoid main(String args[]) {StringBuffer sb = new StringBuffer("Propozitie propusa spre codare.");String newString = sb.toString();

    System.out.println("Sirul inaintea procesului de codare este :" + newString);

    String Final= newString.replaceAll("a", "apa").replaceAll("e","epe").replaceAll("i", "ipi").replaceAll("o", "opo").replaceAll("u", "upu");

    //repleceAll inlocuieste in sirul newString si inlocuieste in Final toatevocalele cu combinatiile corespunzatoare

    System.out.println("Sirul in urma codarii este : " + Final);

    }

    }

  • 7/29/2019 TEMA 2 Programare

    5/6

    Generatorul de numere aleatoare

    function randomString(len, charSet) {

    charSet = charSet ||

    'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

    var randomString = '';

    for (var i = 0; i < len; i++) {

    var randomPoz = Math.floor(Math.random() * charSet.length);

    randomString += charSet.substring(randomPoz,randomPoz+1);

    }

    return randomString;

    }

    Generator 2

    unction randomstring(L){

    var s= '';

    var randomchar=function(){

    var n= Math.floor(Math.random()*62);

    if(n

  • 7/29/2019 TEMA 2 Programare

    6/6

    var nuc = new Array("A", "T", "C", "G")

    var i = 0

    var n = 0

    s = ''

    while (i