File tree Expand file tree Collapse file tree
InterviewPrograms/src/com/java Expand file tree Collapse file tree 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 22
33import java .util .ArrayList ;
44import java .util .Collections ;
5+ import java .util .HashSet ;
56import java .util .Scanner ;
7+ import java .util .TreeSet ;
68
79/*
810 * Divisors of N
@@ -25,7 +27,7 @@ public static void main(String[] args) {
2527 System .out .println ("Enter the N value : " );
2628 int N = Integer .parseInt (scanner .nextLine ().trim ());
2729
28- ArrayList <Integer > divisors = new ArrayList <>();
30+ TreeSet <Integer > divisors = new TreeSet <>();
2931 for (int i =1 ;i <N ;i ++){
3032 int d = N % i ;
3133 if (d == 0 ){
@@ -39,7 +41,6 @@ public static void main(String[] args) {
3941 if (N /i <= i )
4042 break ;
4143 }
42- Collections .sort (divisors );
4344 System .out .println ("The divisors of " +N +" are : " +divisors .toString () );
4445 System .out .println ("Number of Divisors are : " +divisors .size ());
4546 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