Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication19;
- import java.util.Arrays;
- import java.lang.Integer;
- import java.util.Comparator;
- /**
- *
- * @author Student
- */
- public class JavaApplication19 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Integer [] v = {10, 13, 9, 5, 352, 25, 19, 8, 1000, 9999};
- Arrays.sort(v, new Comparator<Integer>(){;
- @Override
- public int compare(Integer c1, Integer c2) //o clasa care poate fi apelata si instanta o singura data in acest context
- {
- if(c1.toString().length() < c2.toString().length())
- return -1;
- return 1;
- }
- });
- for(int i = 0; i < v.length; i++)
- System.out.println(v[i]);
- }
- }
- -------------------------------------------------------------------------------------------
- ENUMERATIE
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package javaapplication21;
- /**
- *
- * @author Student
- */
- public enum CoffeSize {
- BIG(100), HUGE(200), OVERWHELMING(300)
- {
- void afisare()
- {
- System.out.println("b");
- }
- };
- CoffeSize(int ml){
- this.ml = ml;}
- public int getMl() {
- return ml;
- }
- private int ml;
- void afisare(){
- System.out.println("A");}
- }
- -------------------------------------------------------------------------------------
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package JavaApplication24;
- import java.io.FileNotFoundException;
- /**
- *
- * @author Student
- */
- public class ExpExample {
- /**
- */
- public void couldThrowExp() throws RuntimeException {
- throw new RuntimeException();
- }
- public void couldThrowExp2() throws FileNotFoundException {
- throw new FileNotFoundException();
- }
- public static void main(String[] args) {
- try {
- ExpExample expExample = new ExpExample();
- expExample.couldThrowExp();
- expExample.couldThrowExp2();
- } catch (Exception e) { //nu putem pune un exception e inainte de un runtimeException
- System.out.println("Expectie prinsa filenotfound");
- } catch (RuntimeException e) {
- System.out.println("Expectie prinsa runtimeexp");
- }
- }
- }
- -----------------------------------------------------------------------
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lab7;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Scanner;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- /**
- *
- * @author Student
- */
- public class Fisier {
- public static void main(String[] args) throws FileNotFoundException, IOException
- {
- File file = new File("in.txt");
- Scanner sc = new Scanner (file);
- ArrayList<Integer> list = new ArrayList<Integer>();
- while(sc.hasNext())
- {
- list.add(sc.nextInt());
- }
- Collections.sort(list);
- list.forEach(elem->System.out.println(elem));
- FileWriter scc = new FileWriter("out.txt");
- list.forEach(elem->{
- try {
- scc.write(elem.toString());
- } catch (IOException ex) {
- Logger.getLogger(Fisier.class.getName()).log(Level.SEVERE, null, ex);
- }
- });
- scc.close();
- }
- }
- Citire din fisier
Advertisement
Add Comment
Please, Sign In to add comment