View Single Post
Old 09-09-2012, 05:13 PM   PM User | #1
YA123
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
YA123 is an unknown quantity at this point
Help with basic java project

Enter a long string: My name is YA123
Enter a substring: name
Length of your string:14
Length of your substring:4
Starting position of your substring in string: 4
String before your substring: My
String after your substring: is YA123
Enter a position between 0 and 13: 5
The character at position : a
Enter a replacement string: username
Your new string is: My username is YA123

I need help with this code which probably looks very basic for some of you, but I'm struggling right now.

I have up to length of the substring, as shown in the following code.
Code:
	Scanner keyboard = new Scanner(System.in);
		System.out.print("Enter a long string: ");
		String longSt = keyboard.nextLine();
		System.out.println("Enter a substring: ");
		String substring = keyboard.nextLine();
		int longlength = longSt.length();
		System.out.println("Length of your string: " + longlength);
		int sublength = substring.length();
		System.out.println("Length of your substring: " + sublength);
Can someone please help me, I'm stuck because i don't know how to program finding characters of strings that the user creates.
YA123 is offline   Reply With Quote