anoterCode
This commit is contained in:
parent
922420d5e2
commit
c5974fe278
11
.idea/runConfigurations/Unnamed.xml
Normal file
11
.idea/runConfigurations/Unnamed.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Unnamed" type="Application" factoryName="Application" nameIsGenerated="true">
|
||||
<option name="ALTERNATIVE_JRE_PATH" value="17" />
|
||||
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="true" />
|
||||
<option name="MAIN_CLASS_NAME" value="Amazon" />
|
||||
<module name="MvnDemo" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
||||
36
Amazon.java
Normal file
36
Amazon.java
Normal file
@ -0,0 +1,36 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class Amazon {
|
||||
public static void main(String[] args) {
|
||||
int[] arr = { 4, 4, 4, 4, 1, 1, 1, 1, 1, 6, 6, 6, 6, 3, 3, 3, 3, 2, 2, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 };
|
||||
ArrayList<Integer> al = new ArrayList<>();
|
||||
ArrayList<Integer> all = new ArrayList<>();
|
||||
for (int d = 0; d < arr.length; d++) {
|
||||
Collections.sort(all);
|
||||
all.add(arr[d]);
|
||||
}
|
||||
// for (int i = 0; i < arr.length; i++) {
|
||||
// System.out.print(arr[i]);
|
||||
// System.out.print("\t");
|
||||
// al.add(arr[i]);
|
||||
// }
|
||||
// System.out.println("");
|
||||
// System.out.println(al);
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
int p = 0;
|
||||
if (!al.contains(arr[i])) {
|
||||
al.add(arr[i]);
|
||||
p++;
|
||||
for (int j = 1 + i; j < arr.length; j++) {
|
||||
if (arr[i] == arr[j]) {
|
||||
p++;
|
||||
}
|
||||
}
|
||||
System.out.println(arr[i] + " ==>" + p);
|
||||
}
|
||||
}
|
||||
System.out.println(all);
|
||||
}
|
||||
|
||||
}
|
||||
64
Collectionz.java
Normal file
64
Collectionz.java
Normal file
@ -0,0 +1,64 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Collectionz {
|
||||
public static void main(String[] args) {
|
||||
|
||||
// ArrayList
|
||||
|
||||
ArrayList<Integer> arr = new ArrayList<>();
|
||||
arr.add(45);
|
||||
arr.add(63);
|
||||
arr.add(24);
|
||||
arr.add(65);
|
||||
arr.add(74);
|
||||
arr.add(22);
|
||||
arr.add(3, 100);
|
||||
|
||||
System.out.println(arr);
|
||||
Collections.sort(arr);
|
||||
System.out.println(arr);
|
||||
System.out.println(arr.contains(43));
|
||||
|
||||
// Hashset
|
||||
HashSet<String> hs = new HashSet<>();
|
||||
hs.add("Sami");
|
||||
hs.add("Leena");
|
||||
hs.add("Zakaria");
|
||||
hs.add("Mohammed");
|
||||
hs.add("Sara");
|
||||
hs.add("Chekalil");
|
||||
hs.add("Benmoulay");
|
||||
hs.add("doctor");
|
||||
hs.add("Engineer");
|
||||
|
||||
System.out.println(hs);
|
||||
Iterator<String> it = hs.iterator();
|
||||
while (it.hasNext()) {
|
||||
System.out.println(it.next());
|
||||
}
|
||||
System.out.println("");
|
||||
System.out.println("");
|
||||
System.out.println("");
|
||||
|
||||
// HashMap
|
||||
//
|
||||
HashMap<Integer, String> hm = new HashMap<>();
|
||||
hm.put(0, "Zakaria");
|
||||
hm.put(1, "Sara");
|
||||
hm.put(2, "Leena");
|
||||
hm.put(3, "Sami");
|
||||
System.out.println(hm);
|
||||
Set sm = hm.entrySet();
|
||||
Iterator it2 = sm.iterator();
|
||||
while (it2.hasNext()) {
|
||||
System.out.println(it2.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
14
HashMapAmazon.java
Normal file
14
HashMapAmazon.java
Normal file
@ -0,0 +1,14 @@
|
||||
import java.util.HashMap;
|
||||
|
||||
public class HashMapAmazon {
|
||||
public static void main(String[] args) {
|
||||
int[] ar = { 3, 4, 4, 4, 3, 3, 3, 3, 6, 6, 6, 6, 1, 1, 1, 1, 9 };
|
||||
HashMap<Integer, Integer> elementCount = new HashMap<>();
|
||||
for (int i : ar) {
|
||||
elementCount.put(i, elementCount.getOrDefault(i, 0) + 1);
|
||||
}
|
||||
for (Integer key : elementCount.keySet()) {
|
||||
System.out.println("Element: " + key + " Count: " + elementCount.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
13
JavaClasses.java
Normal file
13
JavaClasses.java
Normal file
@ -0,0 +1,13 @@
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class JavaClasses {
|
||||
public static void main(String[] args) {
|
||||
Date date = new Date();
|
||||
SimpleDateFormat s = new SimpleDateFormat("dd/M/yyyy");
|
||||
SimpleDateFormat sd = new SimpleDateFormat("dd/M/yyyy hh:mm:ss");
|
||||
System.out.println(s.format(date));
|
||||
System.out.println(sd.format(date));
|
||||
System.out.println(date.toString());
|
||||
}
|
||||
}
|
||||
12
SortedArray.java
Normal file
12
SortedArray.java
Normal file
@ -0,0 +1,12 @@
|
||||
import java.util.Arrays;
|
||||
|
||||
public class SortedArray {
|
||||
public static void main(String[] args) {
|
||||
int[] ar = { 9, 5, 2, 4, 3, 1, 6, 8, 7 };
|
||||
Arrays.sort(ar);
|
||||
for (int i = 0; i < ar.length; i++) {
|
||||
|
||||
System.out.print(ar[i] + " ");
|
||||
}
|
||||
}
|
||||
}
|
||||
25
src/main/java/Amazon.java
Normal file
25
src/main/java/Amazon.java
Normal file
@ -0,0 +1,25 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Amazon {
|
||||
public static void main(String[] args) {
|
||||
int x = 0;
|
||||
int[] ar = { 3, 4, 4, 4, 3, 3, 3, 3, 6, 6, 6, 6, 1, 1, 1, 1, 9 };
|
||||
ArrayList<Integer> al = new ArrayList<>();
|
||||
for(int i : ar){
|
||||
al.add(ar[i]);
|
||||
if(!al.contains(ar[i])){
|
||||
al.add(ar[i]);
|
||||
++x;
|
||||
for(int j = i + 1; j < ar.length; j++){
|
||||
if(ar[i] == ar[j]){
|
||||
x++;
|
||||
}
|
||||
}
|
||||
System.out.println(ar[i]);
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
src/main/java/Construct.java
Normal file
21
src/main/java/Construct.java
Normal file
@ -0,0 +1,21 @@
|
||||
public class Construct {
|
||||
int year;
|
||||
String model;
|
||||
String make;
|
||||
|
||||
public Construct() {
|
||||
|
||||
}
|
||||
|
||||
public void carMake(String make, String model, int year) {
|
||||
this.model = model;
|
||||
this.make = make;
|
||||
this.year = year;
|
||||
System.out.println("My car by " + year + " is " + make + " - " + model);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Construct car = new Construct();
|
||||
car.carMake("Audi", "RS6", 2025);
|
||||
}
|
||||
}
|
||||
BIN
target/classes/Amazon.class
Normal file
BIN
target/classes/Amazon.class
Normal file
Binary file not shown.
BIN
target/classes/Construct.class
Normal file
BIN
target/classes/Construct.class
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user