Page 6 -
Homework - Alternating vowels and consonants
Page 6 - Discuss Alternating vowels and consonants in the Java Help forum on Dev Shed. Alternating vowels and consonants Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
Posts: 39
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Quote:
Originally Posted by burakaltr
Code:
import javax.swing.JOptionPane;
public class AlternatingVowelsAndConsonants
{
public static void main(String[] args)
{
String userInput,not = "";
char d;
int vow = 0, con = 0;
userInput = JOptionPane.showInputDialog(null, "Enter a word ");
String strippedInput = userInput.replaceAll("\\W", "");
String strippedInput1 = strippedInput.toLowerCase();
int c = strippedInput1.length();
boolean boo=true;
int cnt=0;
boolean bb = true,a = false,b = false;;
String str="yes";
for(int i=0;i<strippedInput1.length()-1;i++){
d = strippedInput1.charAt(i);
char d2=strippedInput1.charAt(i+1);
boolean dV= (d == 'a' || d == 'A' || d == 'e' || d == 'E' || d == 'i' || d == 'I'
|| d == 'o' || d == 'O' || d == 'u' || d == 'U') ;
boolean dC= (d != 'a' && d != 'A' && d != 'e' &&d != 'E' && d != 'i' && d != 'I'
&& d != 'o' && d != 'O' && d != 'u' && d != 'U') ;
boolean d2V= (d2 == 'a' || d2 == 'A' || d2 == 'e' || d2 == 'E' || d2 == 'i' || d2 == 'I'
|| d2 == 'o' || d2 == 'O' || d2 == 'u' || d2 == 'U') ;
boolean d2C= (d2 != 'a' && d2 != 'A' && d2 != 'e' && d2 != 'E' && d2 != 'i' &&d2 != 'I'
&&d2 != 'o' && d2 != 'O' &&d2 != 'u' && d2 != 'U') ;
//System.out.println(dV&&d2V || dC&&d2C);
if(dC&&d2C){
str="NOT";
;
}
if(dV&&d2V){
str="NOT";
; }
/* if(dV&&d2V ==true){
str="NOT"; }
if(dC&&d2C ==true){
str="NOT";
}
*/
/*
if(dV&&d2V){
str="NOT";break;
}
if(dC&&d2C){
str="NOT";break;
}
*/
}
System.out.println(str);
}}
Oh so basically you check if it's not alternating only then say it is if that fails? That is simple I changed my question to checking if a sentence is a palidrome or not, that was easier
Posts: 46
Time spent in forums: 9 h 55 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by ctroop4ever
Oh so basically you check if it's not alternating only then say it is if that fails? That is simple I changed my question to checking if a sentence is a palidrome or not, that was easier
Posts: 39
Time spent in forums: 4 h 15 m 8 sec
Reputation Power: 1
Quote:
Originally Posted by burakaltr
Sir, you disagree , but
" Aurum84 disagrees: remove commented-out code , alot of redundancy in code "
I worked on it and after many updates and re-runs I got it to work and was excited to post it sooner.
I think I do not merit that.
(
I am running it now and it is great to see the program actually working! even if i am not using it it would kill me to never see it actually work, thank you for sitting down and actually figuring it out, i never go on these websites but i was desperate, its nice to know there are people out there that like to help others
Posts: 74
Time spent in forums: 3 Days 23 h 5 m 49 sec
Reputation Power: 17
I agree, there is a difference between "disagree" and "disagree".
I certainly acknowledge your willingness to help the OP in his or her quest for the solution of this java-problem. For that I can only applaud!
You were very keen to provide a solution fast. This, offcourse, is nice for an OP, since the problem is solved, yet there is hardly any room for learning of this solution. But good of you that you held yourself back in that.
I understand that you were very happy to provide the solution after the deadline, and you are more than allowed to do so. The only reason I disagreed on it, was because of the quality of the code.
Posts: 46
Time spent in forums: 9 h 55 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by ctroop4ever
I am running it now and it is great to see the program actually working! even if i am not using it it would kill me to never see it actually work, thank you for sitting down and actually figuring it out, i never go on these websites but i was desperate, its nice to know there are people out there that like to help others
As Far as Better Coding goes...
Code:
import javax.swing.JOptionPane;
public class AlternatingVowelsAndConsonants
{
public static void main(String[] args)
{
String userInput,not = "";
char d;
int vow = 0, con = 0;
userInput = JOptionPane.showInputDialog(null, "Enter a word ");
String strippedInput = userInput.replaceAll("\\W", "");
String strippedInput1 = strippedInput.toLowerCase();
int c = strippedInput1.length();
boolean boo=true;
int cnt=0;
boolean bb = true,a = false,b = false;;
String str="yes";
for(int i=0;i<strippedInput1.length()-1;i++){
d = strippedInput1.charAt(i);
char d2=strippedInput1.charAt(i+1);
boolean dV= Vowel.indexOf(d)!=-1;
boolean dC=Conso.indexOf(d)!=-1;
boolean d2V= Vowel.indexOf(d2)!=-1;
boolean d2C=Conso.indexOf(d2)!=-1;
if(dC&&d2C){
str="NOT";
;
}
if(dV&&d2V){
str="NOT";
; }
}
System.out.println(str);
}
final static String Vowel=
"aeiıou";
final static String Conso=
"bcdfghjklmnpqrstvwxyz";
}
Posts: 2,951
Time spent in forums: 1 Week 6 Days 2 h 29 m 42 sec
Reputation Power: 345
That is poorly documented code.
The variable names could be more descriptive of their purpose.
What value does dC contain?
What are the variables a and b for?