rahul_fda's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 4 (0.01 per day)
- Joined:
- 02-April 12
- Profile Views:
- 157
- Last Active:
Apr 03 2012 09:16 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Consecutive characters in a String [java]
Posted 3 Apr 2012
Can't seem to get rid of OutOfBoundsException.
Here's the code in c. I am not able to get the loop right either. Not here. In java.
#include<stdio.h> #include<conio.h> main() { char str[50]; int i; printf(" Enter String\n"); scanf("%s",str); for(i=0;str[i]!='\0';i++) { if(str[i]==str[i+1]) printf ("%c\n", str[i]); } getch(); }
How do I do it in java? And yes, I am looking for an increase in count the moment it finds pairs. -
In Topic: Consecutive characters in a String [java]
Posted 3 Apr 2012
Here it is.
public class CharRepeat {
public static void main(String[] args){
int count =0;
StringBuilder sb = new StringBuilder("Hello there ppl");
for (int i = 0; i<sb.length()+1; i++){
if (sb.charAt(i) == sb.charAt(i+1))
count++;
}
System.out.println("The count is " +count);
}
}
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Private
Friends
rahul_fda hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
rahul_fda has no profile comments yet. Why not say hello?