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 7 of 7

Thread: a tiny question

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default a tiny question

    hello
    i am a beginer in java world and i have this question

    i want a code to do this

    1- prompt to enter a number
    2-number not less than 1
    3- the output needs to be like this -2+4-6+8-10+12-14+16-18+20 to the number i entered and stops

    thanks in advance


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,372
    Thanks
    184
    Thanked 836 Times in 779 Posts
    Blog Entries
    5

    Default Re: a tiny question

    What did you try? Where are you stuck? What basics of java programming do you know? All these questions boil down to me suggesting you try something to accomplish your tasks, make an attempt and research a bit, ask a specific question about code you have - rather than implying you wish someone else to do it for you.
    Last edited by copeg; May 7th, 2012 at 12:33 AM.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,346
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: a tiny question

    Cross posted at A tiny question - Dev Shed
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: a tiny question

    ok
    this is what i did

    public static void main(String[] args){

    Scanner num = new Scanner (System.in);
    int highestnum;
    int count = 0;
    System.out.println("Enter the number :") ;
    highestnum = num.nextInt();


    while(count<highestnum)
    {
    count= count+2;

    System.out.print(" "+count);
    }


    }

    }
    i cant fuigre out how to put - and + before the output one at a time

    plz help

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,550
    My Mood
    Grumpy
    Thanks
    0
    Thanked 169 Times in 160 Posts

    Default Re: a tiny question

    You can use a boolean and an if statement. If the boolean is true print '+' else print '-'. Print value. Change value of boolean.
    Improving the world one idiot at a time!

  6. #6
    Junior Member
    Join Date
    May 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: a tiny question

    i dont get it
    what the if condition would be so i can put - and + one at a time?

    i get the boolean part

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,346
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: a tiny question

    See my post on the other forum.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Tiny problem with arguments.
    By Melawe in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 15th, 2011, 03:26 PM