Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Poetry{
- public static void main(String [] args) {
- Scanner s=new Scanner(System.in);
- int verses= s.nextInt();
- char[][] lines= new char[verses*4][];
- String[] rhymeType= new String[verses];
- String[] lastSyllable= new String[verses*4];
- s.nextLine();
- for(int i=0; i< verses*4; i++){
- lines[i]=s.nextLine().toLowerCase().toCharArray();
- for( int o= lines[i].length-1; o>-1; o--){
- if(lines[i][o]=='a'||lines[i][o]=='e'||lines[i][o]=='i'||
- lines[i][o]=='o'||lines[i][o]=='u'||lines[i][o]==' '){
- lastSyllable[i]= new String(lines[i], o, (lines[i].length-1)-o);
- break;
- }
- // have to put this else if here, otherwise one letter lines with no vowel or space will
- // just be skipped past on the first go and not be added into lastSyllable
- else if(lines[i].length==1){
- lastSyllable[i]= new String(lines[i]);
- }
- }
- }
- for(int i=0; i< verses*4; i=i+4){// when comparing objects, use object.equals(object) to test whether values are equal,
- // == just tests for reference equality( whether they are same object)
- if(lastSyllable[i].equals(lastSyllable[i+1])&&lastSyllable[i+1].equals(lastSyllable[i+2])&&
- lastSyllable[i+2].equals(lastSyllable[i+3]))
- rhymeType[i/4]="perfect";
- else if(lastSyllable[i].equals(lastSyllable[i+1])&&lastSyllable[i+2].equals(lastSyllable[i+3]))
- rhymeType[i/4]="even";
- else if(lastSyllable[i].equals(lastSyllable[i+2])&&lastSyllable[i+1].equals(lastSyllable[i+3]))
- rhymeType[i/4]="cross";
- else if(lastSyllable[i].equals(lastSyllable[i+3])&&lastSyllable[i+2].equals(lastSyllable[i+1]))
- rhymeType[i/4]="shell";
- else
- rhymeType[i/4]="free";
- }
- for(String xd: rhymeType){
- System.out.println(xd);
- }
- }
- }
Add Comment
Please, Sign In to add comment