Assignment 12 Due Tuesday, May 26 at 11:59pm on Canvas Important: To receive credit, you must only use concepts and methods taught in class to complete these assignments - or You Will Receive a 0 Pair Programming Required (or You Will Receive a 0)
Assignment 12: Strings in a Loop (10 pts)
/** * @author * @author * CIS 36A, Assignment 12 */ import java.util.Scanner; public class StringLoops { public static void main(String[] args) { int n; // the integer number String word, sub, vowels = ""; Scanner input = new Scanner(System.in); System.out.println("** Strings in a Loop!**\n"); System.out.print("Enter an integer between 1 and 20: "); n = input.nextInt(); System.out.print("Enter a word that is at least 2 letters long: "); word = input.next(); System.out.println(); sub = //find substring of first two letters in word here; System.out.println("The first two letters of " + word + " are: " + sub + "\n"); // Repeating the sub n times with a for-loop. System.out.println("#1. Printing " + sub + " " + n + " times:\n"); //Put your code here System.out.println("\n"); // Repeating the sub n times with dot on odd indexes. System.out.println("#2. Printing " + sub + " " + n + " times substituting '.' on odd indexes:\n"); // Put your code here System.out.println("\n"); // Repeating the character n times with minus sign (-) every 5 chars System.out.println("#3. Printing " + sub + " " + n + " times substituting (-) every fifth character:\n"); // Put your code here System.out.println("\n"); System.out.println("#4. Printing " + n + " lines of the previous loop:\n"); // Hint: put your for-loop from the previous challenge inside another // for-loop that has a different counting variable. // Put your code here System.out.println(); System.out.println("#5. Printing all the vowels in " + word + ":\n"); // Hint: use the concepts from lesson 12 to write a for loop //to traverse a String. Note that your for loop should have at least //one if statement. See Activity 12.2 for an example //Put your code here System.out.println(vowels + "\n"); //Printing out the vowels n times, each set of vowels on its own line System.out.println("#6. Printing all the vowels in " + word + " " + n + " times:\n"); //Put your code here System.out.println("\n"); input.close(); } }
** Loopy Strings!** Enter an integer between 1 and 20: 15 Enter a word that is at least 2 letters long: Evidently The first two letters of Evidently are: Ev #1. Printing Ev 15 times: EvEvEvEvEvEvEvEvEvEvEvEvEvEvEv #2. Printing Ev 15 times substituting '.' on odd indexes: .Ev.Ev.Ev.Ev.Ev.Ev.Ev. #3. Printing Ev 15 times substituting (-) every fifth character: EvEvEvEv-EvEvEvEv-EvEvEvEv- #4. Printing 15 lines of the previous loop: EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- EvEvEvEv-EvEvEvEv-EvEvEvEv- #5. Printing all the vowels in Evidently: Eie #6. Printing all the vowels in Evidently 15 times: Eie Eie Eie Eie Eie Eie Eie Eie Eie Eie Eie Eie Eie Eie Eie Example Output 2: ** Loopy Strings!** Enter an integer between 1 and 20: 9 Enter a word that is at least 2 letters long: amazing The first two letters of amazing are: am #1. Printing am 9 times: amamamamamamamamam #2. Printing am 9 times substituting '.' on odd indexes: .am.am.am.am. #3. Printing am 9 times substituting (-) every fifth character: amamamam-amamamam #4. Printing 9 lines of the previous loop: amamamam-amamamam amamamam-amamamam amamamam-amamamam amamamam-amamamam amamamam-amamamam amamamam-amamamam amamamam-amamamam amamamam-amamamam amamamam-amamamam #5. Printing all the vowels in amazing: aai #6. Printing all the vowels in amazing 9 times: aai aai aai aai aai aai aai aai aai
|