File tree 4 files changed +50
-2
lines changed
InterviewPrograms/src/com/java
4 files changed +50
-2
lines changed Original file line number Diff line number Diff line change
1
+ /snippet /
Original file line number Diff line number Diff line change
1
+ package snippet ;
2
+
3
+ public class Snippet {
4
+ Divisors are
5
+ }
6
+
Original file line number Diff line number Diff line change 2
2
3
3
import java .util .ArrayList ;
4
4
import java .util .Collections ;
5
+ import java .util .HashSet ;
5
6
import java .util .Scanner ;
7
+ import java .util .TreeSet ;
6
8
7
9
/*
8
10
* Divisors of N
@@ -25,7 +27,7 @@ public static void main(String[] args) {
25
27
System .out .println ("Enter the N value : " );
26
28
int N = Integer .parseInt (scanner .nextLine ().trim ());
27
29
28
- ArrayList <Integer > divisors = new ArrayList <>();
30
+ TreeSet <Integer > divisors = new TreeSet <>();
29
31
for (int i =1 ;i <N ;i ++){
30
32
int d = N % i ;
31
33
if (d == 0 ){
@@ -39,7 +41,6 @@ public static void main(String[] args) {
39
41
if (N /i <= i )
40
42
break ;
41
43
}
42
- Collections .sort (divisors );
43
44
System .out .println ("The divisors of " +N +" are : " +divisors .toString () );
44
45
System .out .println ("Number of Divisors are : " +divisors .size ());
45
46
scanner .close ();
Original file line number Diff line number Diff line change
1
+ package com .java .patterns ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ /*
6
+ Write a Java Program to print the following Pattern
7
+ 5 5 5 5 5 5 5 5 5
8
+ 4 4 4 4 4 4 4
9
+ 3 3 3 3 3
10
+ 2 2 2
11
+ 1
12
+ */
13
+ public class Pattern10 {
14
+ public static void main (String [] args ) {
15
+ Scanner scanner = new Scanner (System .in );
16
+ System .out .println ("Enter the number of rows to print the pattern :: " );
17
+ int N = Integer .parseInt (scanner .nextLine ().trim ());
18
+ for (int i =N ;i >=1 ;i --){
19
+ for (int j =0 ;j <2 *(N -i );j ++)
20
+ System .out .print (" " );
21
+ for (int j =0 ;j <(2 *i )-1 ;j ++)
22
+ if ( j == 0 )
23
+ System .out .print ("*" );
24
+ else
25
+ System .out .print (" *" );
26
+ if (i > 1 )
27
+ System .out .println ();
28
+ }
29
+ scanner .close ();
30
+ }
31
+ }
32
+ /*
33
+ OUTPUT
34
+ Enter the number of rows to print the pattern :: 5
35
+ 5 5 5 5 5 5 5 5 5
36
+ 4 4 4 4 4 4 4
37
+ 3 3 3 3 3
38
+ 2 2 2
39
+ 1
40
+ */
You can’t perform that action at this time.
0 commit comments