Results 1 to 8 of 8

Thread: two short codes

  1. #1
    Libertyman is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default two short codes

    i need the program to count from 10 to 100 (and present those numbers)



    class Ex2
    {
    public static void main(String[] args)
    {
    int count;
    count=10;
    while(count<90)
    {
    System.out.println(count+1);
    count=count+1;
    }

    }




    }





    i need the program to list all the uneven numbers. that is my code.

    class Ex3
    {
    public static void main(String[] args)
    {
    int count;
    count=0;
    while(count<100)
    {
    System.out.println(count*2-1);
    count=count+1;
    }

    }




    }


    do i have mistakes. if i do, how do i make java do such calculations?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,414
    Blog Entries
    7
    Rep Power
    25

    Default

    Quote Originally Posted by Libertyman View Post
    i need the program to list all the uneven numbers. that is my code.

    class Ex3
    {
    public static void main(String[] args)
    {
    int count;
    count=0;
    while(count<100)
    {
    System.out.println(count*2-1);
    count=count+1;
    }

    }
    }


    do i have mistakes. if i do, how do i make java do such calculations?
    What is printed when count == 0? Why don't you simply run the code and see for yourself?

    kind regards,

    Jos

  3. #3
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    10

    Default

    WTF?! Run the two programs to see whether you get the expected output.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  4. #4
    Libertyman is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    cause my java doesnt work?.. i cant use javac, no idea how to set path and make it work automatically


    and it is also my 2nd lesson in java, therefore , i am clueless

  5. #5
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    10

    Default

    Uhm, it never works automatically.
    Follow these steps:
    "Hello World!" for Microsoft Windows (The Java™ Tutorials > Getting Started > The "Hello World!" Application)

    You should have had it running before the first lesson. This sounds a bit like taking you driver's license test on a bicycle.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,414
    Blog Entries
    7
    Rep Power
    25

    Default

    Quote Originally Posted by Libertyman View Post
    cause my java doesnt work?.. i cant use javac, no idea how to set path and make it work automatically


    and it is also my 2nd lesson in java, therefore , i am clueless
    As I wrote in your other thread: fix your "path" variable.

    kind regards,

    Jos

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    On vacation
    Posts
    19,821
    Rep Power
    29

    Default

    i cant use javac
    Where is the javac.exe file? Find the path to that file then use it:
    C:\Java\jdk1.2\bin\javac.exe Javaprogram.java

    If you give the complete path, the OS doesn't need to find it.

  8. #8
    Libertyman is offline Member
    Join Date
    Jun 2010
    Posts
    26
    Rep Power
    0

    Default

    i had a few mistakes. i found them. i successfuly run javac

Similar Threads

  1. Need help with short problem
    By fataguila in forum New To Java
    Replies: 1
    Last Post: 01-30-2010, 09:58 AM
  2. Short Circuiting?
    By Philly0494 in forum New To Java
    Replies: 12
    Last Post: 11-12-2009, 11:45 AM
  3. Short-cut key
    By tskumarme in forum New To Java
    Replies: 2
    Last Post: 05-28-2008, 04:16 PM
  4. Short/Integer
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-06-2007, 10:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •