Ask your own question, for FREE!
Computer Science 16 Online
OpenStudy (midhun.madhu1987):

How to print the following series in Java: A B B C C C D D D D E E E E E E

OpenStudy (sasogeek):

start by creating a list containing all the alphabet you want, then loop through that list and keep a counter, and for each alphabet, print it as many times as the counter. the counter increases by 1 after each print. so the first one gets printed once, the second gets printed twice, etc. I have the solution, but try writing this algorithm in java and you should have your answer. if you have trouble, post your code here and we'll work on it together :)

OpenStudy (midhun.madhu1987):

Sure... I will make a try and get back to you.. THANKS...!!!

OpenStudy (sasogeek):

No problem :)

OpenStudy (anonymous):

Did the answer work? I am anxious to find out!

OpenStudy (sasogeek):

@pmuldowney have you tried to answer it?

OpenStudy (midhun.madhu1987):

Thanks for your guidelines. It really helped me to solve the problem. Thanks once again. :)

OpenStudy (sasogeek):

anytime :) you mind posting your code though? I'd like to see it :)

OpenStudy (anonymous):

@sasogeek unfortunately I wasn't able to work it....

OpenStudy (sasogeek):

alight so here's my code for it. post yours as well and let's see what you did wrong... could learn a thing or two :) public class alphabet { public static void main(String[] args) { String[] alphabet= {"A ", "B ","C ","D ","E ", "F ", "G ", "I ", "J ", "K "}; for (int i=0; i < alphabet.length; i++) { for (int j=0; j<=i; j++) { System.out.print(alphabet[i]); } System.out.println(""); } } }

OpenStudy (sasogeek):

public class alphabet { public static void main(String[] args) { String[] alphabet= {"A ", "B ","C ","D ","E ", "F ", "G ", "H ", "I ", "J ", "K "}; for (int i=0; i < alphabet.length; i++) { for (int j=0; j<=i; j++) { System.out.print(alphabet[i]); } System.out.println(""); } } }

OpenStudy (midhun.madhu1987):

Hey.. i wrote the 2 methods: package midhun; public class HelloWorld { public static void main(String[] args) { String[] str = {"A","B","C","D","E","F"}; int c=0; System.out.println("METHOD 1"); for(int i=0;i<5;i++) { for(int j=0;j<=i;j++) { System.out.print(str[c]); } System.out.println("\n"); c++; } int counter = 1; System.out.println("METHOD 2"); for(int h=0; h<str.length; h++) { for(int k = 0; k<counter; k++) { System.out.print(str[h]); } System.out.println("\n"); counter++; } } }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!