Skip to content

Commit fd33948

Browse files
committed
collections
1 parent a82ed15 commit fd33948

10 files changed

+163
-0
lines changed

Collection.class

1.37 KB
Binary file not shown.

Collection.java

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import java.util.ArrayList;
2+
import java.util.Collections;
3+
import java.util.List;
4+
import java.util.Scanner;
5+
/**
6+
* @author Dixit
7+
*
8+
*/
9+
public class Collection {
10+
public static void main(String a[]) {
11+
Scanner sc = new Scanner(System.in);
12+
System.out.println("Enter the String:-");
13+
String str = sc.nextLine();
14+
System.out.println("Enter the length");
15+
int count = sc.nextInt();
16+
List<String> list = new ArrayList<String>();
17+
for (int i = 0; i < str.length(); i = i + 1) {
18+
if (str.length() - i >= count) {
19+
list.add(str.substring(i, count + i));
20+
}
21+
}
22+
Collections.sort(list);
23+
System.out.println("Smallest subString:-" + list.get(0));
24+
System.out.println("Largest subString:-" + list.get(list.size() - 1));
25+
}
26+
}

Matrix_diagonal.class

964 Bytes
Binary file not shown.

Matrix_diagonal.java

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* Finding the difference of diagonals in a matrix.........
2+
........................................
3+
..........................................*/
4+
5+
import java.util.Scanner;
6+
7+
public class Matrix_diagonal
8+
9+
{
10+
11+
public static void main(String[] args)
12+
13+
{
14+
15+
int m, n;
16+
17+
18+
Scanner s = new Scanner(System.in);
19+
20+
System.out.print("Enter matrix size:");
21+
22+
m= n = s.nextInt(); //size of matrix..
23+
int a[][] = new int[m][n];
24+
25+
System.out.println("Enter all the elements of first matrix:");
26+
27+
for (int i = 0; i < m; i++)
28+
29+
{
30+
31+
for (int j = 0; j < n; j++)
32+
33+
{
34+
35+
a[i][j] = s.nextInt();
36+
37+
}
38+
}
39+
int d1=0 , d2= 0;
40+
for(int i=0; i<n;i++) {
41+
d1+=a[i][i]; /* diagonal first , 0,0, 1,1, 2,2 ......*/
42+
d2+=a[i][n-i-1]; /* diagonal first , 3,0, 2,1, 1,0 ......*/
43+
}
44+
45+
System.out.println(d1);
46+
System.out.println(d2);
47+
48+
int diff = d1-d2;
49+
// for(int i=0;i<n;i++) //printing the array.
50+
// {
51+
// for (int j=0;j<m;j++)
52+
// {
53+
// System.out.print(a[i][j]+" ");
54+
// }
55+
// System.out.println("\n");
56+
// }
57+
58+
59+
}
60+
}
61+

NumLoop.class

438 Bytes
Binary file not shown.

NumLoop.java

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
public class NumLoop{
3+
public static void main(String[] args) {
4+
// for(float f=5; f<2000; f += 2.5)
5+
// {
6+
// if(f% 2.5 == 0)
7+
// {
8+
// System.out.println(f);
9+
// }
10+
11+
// }
12+
//double n= (7.5 % 2.5) ;
13+
//System.out.println(n);
14+
for(int i= 5; i< 2000;i+=5){
15+
16+
System.out.println(i);
17+
}
18+
}
19+
}

Substr.class

930 Bytes
Binary file not shown.

Substr.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* Printing the sub-string of an string*/
2+
3+
4+
import java.io.*;
5+
import java.util.*;
6+
import java.text.*;
7+
import java.math.*;
8+
import java.util.regex.*;
9+
10+
public class Substr {
11+
12+
public static void main(String[] args) {
13+
Scanner userInput = new Scanner(System.in);
14+
String name = userInput.nextLine();
15+
char[] nameArray = name.toCharArray();
16+
int len=name.length();
17+
//System.out.println(len);
18+
int start = userInput.nextInt();
19+
int end = userInput.nextInt();
20+
21+
if(start <len && end <=len){
22+
for(int i=start;i<end;i++)
23+
{
24+
System.out.print(nameArray[i]);
25+
}
26+
}
27+
else{
28+
System.out.println("incorrct length");
29+
}
30+
31+
}
32+
}

Substr1.class

1.04 KB
Binary file not shown.

Substr1.java

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.io.*;
2+
import java.util.*;
3+
import java.text.*;
4+
import java.math.*;
5+
import java.util.regex.*;
6+
7+
public class Substr1{
8+
public static void main(String[] args) {
9+
Scanner sc = new Scanner(System.in);
10+
String str = sc.nextLine();
11+
int k = sc.nextInt(); // size of sub string
12+
13+
SortedSet<String> sets=new TreeSet<String>();
14+
for(int i=0;i<str.length()-k+1;i++)
15+
{
16+
sets.add(str.substring(i,i+k));
17+
System.out.println(sets);
18+
// break;
19+
}
20+
System.out.println(sets.first());
21+
System.out.println(sets.last());
22+
23+
}
24+
25+
}

0 commit comments

Comments
 (0)