Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: print A-Z without O I J

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default print A-Z without O I J

    char[]chr=new char[21];
    	int i=0; chr[0]='A';
    	for(i=1; i<20 && chr[i]!='I' && chr[i]!='O' && chr[i]!='J';i++){
    		chr[i]=++(chr[i-1]);}
    		System.out.println(Arrays.toString(chr));
    I want to print charactor from A-Z without I O J; above is my code.
    and the result is [B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, T,
    would any one pls tell me why
    1, i assigment char[0] as 'A' out of for loop, why chr[0] is B?
    2 and most confused me, why STILL have I O J????
    THANK YOU!


  2. #2
    Forum VIP
    Join Date
    Jun 2011
    Posts
    232
    My Mood
    Stressed
    Thanks
    36
    Thanked 66 Times in 54 Posts
    Blog Entries
    4

    Default Re: print A-Z without O I J

    int i=0; chr[0]='A';

    What is the very next thing that happens to this variable 'i'?

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: print A-Z without O I J

    ok, i have a type mistake, should be
    int i
    and i assign as 1 in for loop.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: print A-Z without O I J

    Why try to write such clever code? Change it to simple steps with an if statement
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: print A-Z without O I J

    i am amateur. i try to use if statement, but i can't.
    Soooo nice if any one could help.

  6. #6
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default

    How would you do it without a computer. Write out your steps in plain language on paper and be specific. Once you have that try and write these steps/tests as code.

    Keep the loop simple. Let it count only. Do all of your conditional tests in the body of the loop.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: print A-Z without O I J

    i am amateur.
    	for(i=1; i<20 && chr[i]!='I' && chr[i]!='O' && chr[i]!='J';i++){
    		chr[i]=++(chr[i-1]);
    Where did you get that code? It doesn't look like what a beginner would write.

    What do you want for the contents of the array? Show what the first 15 elements would be.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Nov 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: print A-Z without O I J

    Quote Originally Posted by Norm View Post
    	for(i=1; i<20 && chr[i]!='I' && chr[i]!='O' && chr[i]!='J';i++){
    		chr[i]=++(chr[i-1]);
    Where did you get that code? It doesn't look like what a beginner would write.

    What do you want for the contents of the array? Show what the first 15 elements would be.
    thank you for you reply. i have fingerout my problem. i used ++(chr[i-1]), then ,when programs runs, chr0-> chr1, and it changged itslef also.

  9. #9
    Junior Member
    Join Date
    Dec 2013
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: print A-Z without O I J

    check this code
    ...
    Last edited by copeg; December 15th, 2013 at 09:55 AM. Reason: Removed spoonfed code

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,661
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: print A-Z without O I J

    @sam965 Pleae don't spoonfeed code. See: The Problem with Spoon-feeding
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. CANT PRINT
    By yahel_s7 in forum Java IDEs
    Replies: 5
    Last Post: November 1st, 2013, 06:16 AM
  2. CANT PRINT
    By yahel_s7 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 31st, 2013, 12:59 PM
  3. Print just what I want, help me with my code.
    By JosPhantasmE in forum What's Wrong With My Code?
    Replies: 44
    Last Post: January 22nd, 2013, 06:44 PM
  4. Replies: 1
    Last Post: December 3rd, 2012, 01:35 PM
  5. xfa.host.print: print a page + some page range.
    By gammaman in forum Totally Off Topic
    Replies: 2
    Last Post: May 10th, 2012, 08:07 AM