Created
August 18, 2020 08:31
-
-
Save AakashCode12/d4c6ccfcdfee4bec5f7716ce484d635d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class StringBufferDemo | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner sc = new Scanner(System.in); | |
StringBuffer s = new StringBuffer(20); | |
System.out.print("Enter The String:"); | |
s.append(sc.nextLine()); | |
System.out.println("Length of Your String is : "+s.length()); | |
System.out.println("Capacity of Your String is : "+s.capacity()); | |
System.out.print("Enter another String to be Appended: "); | |
s.append(sc.nextLine()); | |
System.out.println("The String after Appending is: "+s); | |
System.out.print("Enter an Integer to be Appended: "); | |
s.append(sc.nextInt()); | |
System.out.println("The String after Appending is:"+s); | |
System.out.print("Enter a character to be inserted along with its position:"); | |
char ch = sc.next().charAt(0); | |
s.insert(sc.nextInt()-1,ch); | |
System.out.println("The String after Insertion is: "+s); | |
System.out.println("The Reverse of the String is:"+s.reverse());//Reverse Function in the Documentation | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class StringClass | |
{ | |
public static void main(String[] args){ | |
String s; | |
Scanner sc = new Scanner(System.in); | |
System.out.print("Enter Your String : "); | |
s = sc.nextLine(); | |
int length =s.length(); | |
System.out.println("The Length Of The String : "+length); | |
System.out.println("The Middle Character element of the string is: "+s.charAt(length/2)); | |
System.out.println("Enter another String to be Concatenated to the previous one: "); | |
String b=sc.next(); | |
System.out.println("The Concatenated Strings are : "+s.concat(b)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment