File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ public class Fibonacci {
3
+ public static void main (String [] args ) {
4
+
5
+ //Prints first 12 fibonacci series numbers
6
+ int n = 12 , t1 = 0 , t2 = 1 ;
7
+ System .out .print ("First " + n + " terms: " );
8
+
9
+ for (int i = 1 ; i <= n ; ++i )
10
+ {
11
+ System .out .print (t1 + " + " );
12
+
13
+ int sum = t1 + t2 ;
14
+ t1 = t2 ;
15
+ t2 = sum ;
16
+ }
17
+ }
18
+ }
Original file line number Diff line number Diff line change
1
+
2
+ public class HelloWorld_OneCharEverySecond {
3
+ public static void main (String [] args ) throws InterruptedException {
4
+ String helloWorld = "Hello, World!" ;
5
+
6
+ for (char c :helloWorld .toCharArray ()) {
7
+ System .out .print (c );
8
+ Thread .sleep (1000 );
9
+ }
10
+ }
11
+ }
Original file line number Diff line number Diff line change
1
+
2
+ public class Palindrome {
3
+
4
+ // Function that returns true if
5
+ // str is a palindrome
6
+ static boolean isPalindrome (String str )
7
+ {
8
+
9
+ // Pointers pointing to the beginning
10
+ // and the end of the string
11
+ int i = 0 , j = str .length () - 1 ;
12
+
13
+ // While there are characters to compare
14
+ while (i < j ) {
15
+
16
+ // If there is a mismatch
17
+ if (str .charAt (i ) != str .charAt (j ))
18
+ return false ;
19
+
20
+ // Increment first pointer and
21
+ // decrement the other
22
+ i ++;
23
+ j --;
24
+ }
25
+
26
+ // Given string is a Palindrome
27
+ return true ;
28
+ }
29
+
30
+ // Test code
31
+ public static void main (String [] args )
32
+ {
33
+ String str = "wow" ;
34
+
35
+ if (isPalindrome (str ))
36
+ System .out .print ("Yes" );
37
+ else
38
+ System .out .print ("No" );
39
+ }
40
+ }
41
+
42
+
You can’t perform that action at this time.
0 commit comments