|
| 1 | +package random; |
| 2 | + |
| 3 | +public class Concep { |
| 4 | + |
| 5 | + public static void main(String[] args) { |
| 6 | + String s1= new String("hello world"); |
| 7 | + System.out.println(s1.charAt(3)); |
| 8 | + s1.length();//Returns the length of this string |
| 9 | + System.out.println(s1.contains("o")); |
| 10 | + System.out.println(s1.contains("f")); |
| 11 | + |
| 12 | + |
| 13 | + char[] chr = {'a','b','c'}; |
| 14 | + char[] car = {'h','e','d','a',' ','s',' '}; |
| 15 | + |
| 16 | + String cop = String.copyValueOf(car); |
| 17 | + System.out.println(cop); |
| 18 | + |
| 19 | + String check = String.copyValueOf(car, 2, 4); |
| 20 | + System.out.println(check); |
| 21 | + |
| 22 | + |
| 23 | + String name="MyName"; |
| 24 | + int number=50; |
| 25 | + |
| 26 | + String formattedString = String.format("Hello my name is %s and i am %d years old", name, number); |
| 27 | + |
| 28 | + System.out.println("Example 1 : "+formattedString); |
| 29 | + |
| 30 | + |
| 31 | + double pi = 3.14159265; |
| 32 | + formattedString = String.format("The value of pi is approximately %.2f", pi); |
| 33 | + System.out.println("Example 2 : "+formattedString); |
| 34 | + |
| 35 | + int a = 10; |
| 36 | + System.out.println(a); |
| 37 | + a = 11; |
| 38 | + System.out.println(a); |
| 39 | + |
| 40 | + int age = 3; |
| 41 | + formattedString = String.format("her age is %010d", age); |
| 42 | + System.out.println("example 3: "+formattedString); |
| 43 | + |
| 44 | + |
| 45 | + String text ="Hello World"; |
| 46 | + boolean isStrtWit=text.startsWith("H");//true |
| 47 | + boolean isStrtWit2=text.startsWith("o");//false |
| 48 | + boolean isStrtWit3=text.startsWith("h");//false |
| 49 | + |
| 50 | + |
| 51 | + System.out.println(isStrtWit+" "+isStrtWit2+" "+isStrtWit3); |
| 52 | + |
| 53 | + } |
| 54 | + |
| 55 | +} |
0 commit comments