Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class MainClassCreatedByIdea {
- public static void main(String[] args) {
- /** This the documentation of this for cycle */
- /* simple text */
- // comment for me
- for (int i = 0; i < args.length; i++){
- System.out.println("args[" + i + "] = " + args[i]);
- }
- int decVal = 26;
- System.out.println("decVal = " + decVal);
- int hexVal = 0x1b;
- System.out.println("hexVal = " + hexVal);
- int binVal = 0b0100010111;
- System.out.println("binVal = " + binVal);
- float f1 = 432.4f;
- System.out.println("f1 = " + f1);
- double d1 = 1.23123;
- System.out.println("d1 = " + d1);
- System.out.println("-----------------------");
- System.out.println(" Milne said \" this great\". This sentence \'i\'\'s\' full of chars");
- // 1 / 2 = 0!!! if we are using integers
- System.out.println("-----------------------");
- int a = 2;
- int b = 1;
- System.out.println(b / a);
- float c = b / a;
- System.out.println(c);
- //Enhanced for statement
- System.out.println("-----------------------");
- int[] numbers = {1, 2, 3, 4, 5, 6};
- for (int stg : numbers){
- System.out.println("Stg is: " + stg);
- }
- // List creating
- System.out.println("-----------------------");
- List theList = new ArrayList();
- theList.add("String");
- theList.set(0, "String1 overwritten");
- theList.remove(0);
- // Create a list where you put the same element more than once and literate over it enhance for!
- //Create two lists and merge them into a third one by interweaving them
- // Create a list of integers and separate even and odd numbers into two separate lists!
- // Find the maximum element of the lists!
- System.out.println("-----------------------");
- List<Integer> list1 = new ArrayList();
- list1.add(0, 2);
- list1.add(1, 2);
- list1.add(2, 4);
- list1.add(3, 5);
- list1.add(4, 3);
- List<Integer> list2 = new ArrayList();
- list2.add(0, 5);
- list2.add(1, 7);
- list2.add(2, 9);
- list2.add(3, 412);
- list2.add(4, 444);
- for (Integer list2ToPrint : list2){
- System.out.println("this is one element of list2: " + list2ToPrint);
- }
- System.out.println("-----------------------");
- List<Integer> listSum = new ArrayList<>();
- for (int i = 0; i < list2.size(); i++) {
- listSum.add(list1.get(i));
- listSum.add(list2.get(i));
- }
- System.out.println(listSum);
- System.out.println("-----------------------");
- List<Integer> listOdd = new ArrayList<>();
- List<Integer> listEven = new ArrayList<>();
- for (int i = 0; i < listSum.size(); i++){
- if (listSum.get(i) % 2 == 1){
- listOdd.add(listSum.get(i));
- } else {
- listEven.add(listSum.get(i));
- }
- }
- System.out.println("listOdd = " + listOdd);
- System.out.println("listEven = " + listEven);
- System.out.println("-----------------------");
- // Create a set where you put the same element more than once and iterate over it with the enhanced for!
- // Create two sets and merge them into a third and print the elements!
- // Create a set of integers and separate even and odd numbers into two separate sets!
- // Find the maximum element of the set!
- Set<Integer> setContainer = new TreeSet();
- setContainer.add(333);
- setContainer.add(3);
- setContainer.add(5);
- setContainer.add(6);
- setContainer.add(6);
- setContainer.add(6);
- setContainer.add(38);
- setContainer.add(3);
- for (Object enhancedBehavior : setContainer){
- System.out.println("enhancedBehavior = " + enhancedBehavior);
- }
- Set<Integer> setContainer2 = new TreeSet();
- setContainer2.add(3);
- setContainer2.add(2);
- setContainer2.add(77);
- setContainer2.add(43);
- setContainer2.add(55);
- setContainer2.add(66);
- setContainer2.add(88);
- Set<Integer> thirdContainer = new TreeSet();
- for (Integer s1elem : setContainer){
- thirdContainer.add(s1elem);
- }
- for (Integer s2elem : setContainer2){
- thirdContainer.add(s2elem);
- }
- System.out.println("thirdContainer = " + thirdContainer);
- Set<Integer> oddSet = new TreeSet();
- for (Integer oddNr : thirdContainer ){
- if (oddNr % 2 == 1){
- oddSet.add(oddNr);
- }
- }
- System.out.println("oddSet = " + oddSet);
- Set<Integer> evenSet = new TreeSet();
- for (Integer eventNr : thirdContainer){
- if (eventNr % 2 == 0){
- evenSet.add(eventNr);
- }
- }
- System.out.println("evenSet = " + evenSet);
- System.out.println("-----------------------");
- //MAP using
- //create map width my nex shopping list (key= product name, value = price)
- //Print out my shopping list and the price of them
- //store also the quantity of each shopping list netry and calculate price using aso the quality
- Map<String, Integer> shoppingList1 = new Hashtable<>();
- shoppingList1.put("cheese", 1200);
- shoppingList1.put("milk", 200);
- shoppingList1.put("nutella", 1000);
- shoppingList1.put("orange", 800);
- shoppingList1.put("fish", 4200);
- Map<String, Integer> list1qty = new Hashtable<>();
- list1qty.put("cheese", 2);
- list1qty.put("milk", 1);
- list1qty.put("nutella", 1);
- list1qty.put("orange", 6);
- list1qty.put("fish", 3);
- for (Object key1 : shoppingList1.keySet()){
- System.out.println("The " + key1 + " costs: " + shoppingList1.get(key1) * list1qty.get(key1) + " Huf");
- }
- Map<String, Integer> shoppingList2 = new Hashtable<>();
- shoppingList2.put("egg", 930);
- shoppingList2.put("tuna", 1400);
- shoppingList2.put("apple", 1200);
- shoppingList2.put("tobacco", 1100);
- shoppingList2.put("potato", 400);
- Map<String, Integer> list2qty = new Hashtable<>();
- list2qty.put("egg", 12);
- list2qty.put("tuna", 2);
- list2qty.put("apple", 6);
- list2qty.put("tobacco", 1);
- list2qty.put("potato", 22);
- for (Object key2 : shoppingList2.keySet()){
- System.out.println("The " + key2 + " costs: " + shoppingList2.get(key2) * list2qty.get(key2) + " good Hungarian forint");
- }
- Map<String, Integer> shoppingList3 = new Hashtable<>();
- shoppingList3.put("milk", 220);
- shoppingList3.put("sugar", 380);
- shoppingList3.put("wc_papper", 1400);
- shoppingList3.put("cat_food", 2200);
- shoppingList3.put("onion", 410);
- Map<String, Integer> list3qty = new Hashtable<>();
- list3qty.put("milk", 2);
- list3qty.put("sugar", 1);
- list3qty.put("wc_papper", 24);
- list3qty.put("cat_food", 12);
- list3qty.put("onion", 4);
- for (Object key3 : shoppingList3.keySet()){
- System.out.println("This product costs " + shoppingList3.get(key3) * list3qty.get(key3) + " much money.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement