Nov 29, 2015 at 10:43pm Nov 29, 2015 at 10:43pm UTC
I do not think that is JAVA. Nevertheless, I would convert it to C++ like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <string>
int main()
{
std::string a;
std::cout << "Enter a string\n" ;
std::cin >> a;
for (int i = 0; i < a.length(); i++)
{
if (a[i] == a[i + 1])
std::cout << a[i] << " is consecutive\n" ;
}
return 0;
}
The least preferred method, in my opinion is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <cstring>
int main()
{
char a[30];
std::cout << "Enter a string\n" ;
std::cin >> a;
for (int i = 0; i < strlen(a); i++)
{
if (a[i] == a[i + 1])
std::cout << a[i] << " is consecutive\n" ;
}
return 0;
}
Last edited on Nov 29, 2015 at 10:46pm Nov 29, 2015 at 10:46pm UTC
Nov 29, 2015 at 10:47pm Nov 29, 2015 at 10:47pm UTC
thanks man it worked great on my compiler its great to know that there's people out there who are willing to help I've been stressed out a lot from c++ programming. much appreciated buddy