Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[]args){
- Scanner input = new Scanner(System.in);
- int nameCapacity, addressCapacity;
- String inputName, inputAddress;
- System.out.print("Enter a name: ");
- inputName = input.nextLine();
- StringBuilder name = new StringBuilder().append(inputName);
- nameCapacity = name.capacity();
- System.out.println("Capacity of name is " + nameCapacity);
- System.out.print("\nEnter an address: ");
- inputAddress = input.nextLine();
- StringBuilder address;
- address = new StringBuilder(inputAddress);
- addressCapacity = address.capacity();
- System.out.println("Capacity of address is " + addressCapacity);
- System.out.println("\nName length is: " + name.length());
- System.out.println("Address length is: " + address.length());
- System.out.println("\nName is " + name);
- System.out.println("Address is " + address);
- name.setLength(5);
- address.setLength(5);
- System.out.println("\nName length changed to: " + name.length());
- System.out.println("Address length changed to: " + address.length());
- System.out.println("\nName after length change is " + name);
- System.out.println("Address after length change is " + address);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement