Results 1 to 7 of 7
  1. #1
    Plato is offline Member
    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    Default Is there a better way of doing this?

    Is there a better way of doing what I have done with the code provided? Sorry, I'm still a little new and don't have a teacher.

    Java Code:
    public class Main {
    
    	/**
    	 * The Method used to start the program.
    	 * 
    	 * @param args
    	 */
    	public static void main(String[] args) {
    
    		int javamain = 15;
    		int javaclass = 50;
    
    		for (int i = 0; i <= 100; i++) {
    			System.out.println(i);
    			if (i >= 60) {
    				System.out.println("We have stopped.");
    				break;
    			}
    		}
    
    		if (javamain <= 10 && javaclass >= 25) {
    			System.out.println("We have entered the Java Development.");
    		} else {
    			System.out.println("We have not entered the Java Development");
    		}
    
    	}
    
    }
    Last edited by Plato; 09-01-2013 at 04:23 PM.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,104
    Rep Power
    6

    Default Re: Is there a better way of doing this?

    Does it do what you expect it to do? Its not clear at all what the purpose is, as it is now it will always print "we have not entered the java development".
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Is there a better way of doing this?

    Quote Originally Posted by Plato View Post
    Is there a better way of doing this?
    Please go through the Forum Rules with special reference to the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Plato is offline Member
    Join Date
    Sep 2013
    Posts
    3
    Rep Power
    0

    Default Re: Is there a better way of doing this?

    Quote Originally Posted by gimbal2 View Post
    Does it do what you expect it to do? Its not clear at all what the purpose is, as it is now it will always print "we have not entered the java development".
    I didn't know what else to put. But in general, if there is a way to print out the same but with less lines of code? The code in OP is not supposed to mean anything. I just made random varables and made them be used.
    Last edited by Plato; 09-01-2013 at 04:59 PM.

  5. #5
    Ubiquitous is offline Member
    Join Date
    Sep 2013
    Posts
    10
    Rep Power
    0

    Default Re: Is there a better way of doing this?

    It is hard for anyone to give you advice when there is no goal specified. As you mentioned you are just creating variables and assigning values to them, running through a loop and breaking once a condition is met, and the last portion is comparing the assigned values before the loop with some set values in the if statement.

    You may want to learn about naming conventions for variables. For example javamain to javaMain if I remember correctly it's camel case or mixed case not sure but it's just a way to keep long descriptive variable names easier to read.

    As for the rest of the code nothing seems particularly wrong with it since there is no goal other then you learning. If you have any questions in particular with an issue or understanding how something works then that would be a more appropriate post.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,104
    Rep Power
    6

    Default Re: Is there a better way of doing this?

    The only thing I find wrong is the apparent need to reduce the lines of code. Focus on keeping your code readable, not compact.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    pianodave1984's Avatar
    pianodave1984 is offline Aspiring Javaman
    Join Date
    Sep 2013
    Location
    West Chester PA
    Posts
    8
    Rep Power
    0

    Default Re: Is there a better way of doing this?

    Quote Originally Posted by gimbal2 View Post
    The only thing I find wrong is the apparent need to reduce the lines of code. Focus on keeping your code readable, not compact.
    What he said

Posting Permissions

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