File tree Expand file tree Collapse file tree 3 files changed +110
-0
lines changed
Expand file tree Collapse file tree 3 files changed +110
-0
lines changed Original file line number Diff line number Diff line change 1+ package Java_Technical_Training ;
2+
3+ import java .util .Scanner ;
4+
5+ public class ReverseNumber {
6+
7+ int numberOfDigits (int n ) {
8+ int i = 0 ;
9+ while (n != 0 ) {
10+ i ++;
11+ n /= 10 ;
12+ }
13+ return i ;
14+ }
15+
16+ public static void main (String [] args ) {
17+ Scanner sc = new Scanner (System .in );
18+ System .out .print ("Enter the number to reverse : " );
19+
20+ int n = sc .nextInt ();
21+ System .out .println ("The original number is : " + n );
22+
23+ int result = reverse (n );
24+ System .out .println ("The reversed number is : " + result );
25+ sc .close ();
26+ }
27+
28+ static int reverse (int n ) {
29+ int r = 0 , sum = 0 ;
30+ while (n != 0 ) {
31+ r = n % 10 ;
32+ sum = sum * 10 + r ;
33+ n = n / 10 ;
34+ }
35+ return sum ;
36+ }
37+ }
38+
39+ // final int x = numberOfDigits(n);
40+ // if (numberOfDigits(n) == numberOfDigits(result))
41+ // System.out.println("The reversed number is : " + result);
42+ // else {
43+
44+ // }
45+
Original file line number Diff line number Diff line change 1+ package Java_Technical_Training ;
2+
3+ import java .util .Scanner ;
4+
5+ public class SeedNumber {
6+ public static void main (String [] args ) {
7+
8+ Scanner sc = new Scanner (System .in );
9+ System .out .print ("Enter the seed number : " );
10+ int x = sc .nextInt ();
11+ System .out .print ("Enter the second number : " );
12+ int y = sc .nextInt ();
13+
14+ int seed = x ;
15+ int num = x ;
16+ while (seed != 0 ) {
17+ num = num * (seed % 10 );
18+ seed = seed / 10 ;
19+ }
20+ if (num == y ) {
21+ System .out .println (x + " is seed of " + y );
22+ } else {
23+ System .out .println (x + " is not seed of " + y );
24+ }
25+ sc .close ();
26+ }
27+ }
28+
29+ // // if (x >= y) {
30+ // // x = x + y;
31+ // // y = x - y;
32+ // // x = x - y;
33+ // // } // swaping the values
34+ // int a = x, b = x;
35+
36+ // System.out.println("the numbers are " + a + " and " + b);
37+
38+ // while (b != 0) {
39+ // a = b * (b % 10);
40+ // b /= 10;
41+ // }
42+ // if (a == y) {
43+ // System.out.println(x + " is a seed of " + y);
44+ // System.exit(a);
45+ // }
46+ // System.out.println(x + " is not a seed of " + y);
Original file line number Diff line number Diff line change 1+ package Java_Technical_Training ;
2+
3+ import java .util .Scanner ;
4+
5+ public class SumOfSeries {
6+ public static void main (String [] args ) {
7+ Scanner sc = new Scanner (System .in );
8+ System .out .print ("Enter the number " );
9+ int n = sc .nextInt ();
10+ double sum = 0 ;
11+
12+ for (int i = 1 ; i <= n ; i ++) {
13+ sum += Math .pow (i , -1 );
14+ }
15+ System .out .println ("The sum of series of " + n + " numbers is " + sum );
16+ sc .close ();
17+ }
18+
19+ }
You can’t perform that action at this time.
0 commit comments