Conjoint Gaming [Game On]

CG Technical Area => Programming => Topic started by: Mr. Commodore on May 05, 2012, 06:13:56 AM

Title: [Java] Number Evaluator (Positive, negative, zero)
Post by: Mr. Commodore on May 05, 2012, 06:13:56 AM
Code: [Select]
import java.util.Scanner;

public class numberEvaluator {
 public static int number;
 public static void evaluator(){
   if(number == 0){
    System.out.println("Zero.");
   }else if(number % 2 == 0){
    System.out.println("Even.");
   } else {
    System.out.println("Odd.");
   }
   numberEvaluator.main(null);
 }
  public static void main(String [] args){
    Scanner sc = new Scanner(System.in);
    number = sc.nextInt();
    numberEvaluator.evaluator();
  }
}

Did this for an intro to programming class, got a hundred  Meme6


Should revive this board...
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: Blackllama on May 05, 2012, 06:36:56 AM
wouldn't
Code: [Select]
(number % 2 == 0) mean it's even? Pretty sure the modulos operator divides it and takes the remainder, which would mean it's an even number if divided by two and has no remainder.

If you want to see if it's positive just do
Code: [Select]
(number > 0)
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: Mr. Commodore on May 05, 2012, 06:54:56 AM
wouldn't
Code: [Select]
(number % 2 == 0) mean it's even? Pretty sure the modulos operator divides it and takes the remainder, which would mean it's an even number if divided by two and has no remainder.

If you want to see if it's positive just do
Code: [Select]
(number > 0)

That would be a derp on my use of words, positive = even, negative = odd.
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: Zukuto on May 05, 2012, 11:26:55 AM
Code: [Select]
import java.util.Scanner;

public class numberEvaluator {
 public static int number;
 public static void evaluator(){
   if(number == 0){
    System.out.println("Zero.");
   }else if(number % 2 == 0){
    System.out.println("Even.");
   } else {
    System.out.println("Odd.");
   }
   numberEvaluator.main(null);
 }
  public static void main(String [] args){
    Scanner sc = new Scanner(System.in);
    number = sc.nextInt();
    numberEvaluator.evaluator();
  }
}

Did this for an intro to programming class, got a hundred  Meme6


Should revive this board...

Nice job!

However, your organization disgusts me. D:
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: Mr. Commodore on May 05, 2012, 07:29:32 PM
Nice job!

However, your organization disgusts me. D:

That's due to Dr. Java. I NEVER want to use it, but for the purposes for the class its really helpful in debugging.
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: Blackllama on May 06, 2012, 12:21:07 AM
Dude, get eclipse.
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: Sprite on May 06, 2012, 12:53:45 AM
Ya really why are you using Dr. Java eclipse is 100 times better
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: Mr. Commodore on May 06, 2012, 01:05:13 AM
Have and do use eclipse.

For the purpose of a few assignments in the class that involve manipulating objects in a 2d environment, the interactions pane is actually REALLY helpful. Only really use it for fine tuning what I do in eclipse, and it puts it in a retarded format.
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: TRMayhem on March 07, 2013, 09:35:09 PM
I like this, but I would think there is better ways of doing this. I wouldn't say my way is better but I would do it like this:

http://paste.ubuntu.com/5594613/

Sorry I use ubuntu paste just to ensure that thread isn't spammed with code.
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: Blackllama on March 07, 2013, 09:58:24 PM
I like this, but I would think there is better ways of doing this. I wouldn't say my way is better but I would do it like this:

http://paste.ubuntu.com/5594613/

Sorry I use ubuntu paste just to ensure that thread isn't spammed with code.
I agree, it makes more sense if you pass in the parameter. Although I find the
Code: [Select]
NumberEvaluator.main(null);kind of weird. I've never seen that before. It serves its purpose though. If I wanted the program to run forever I would just use an infite while loop or something.

That post was quite a necro by the way. This thread is like 10 months old. The board does still need more posting.
Title: Re: [Java] Number Evaluator (Positive, negative, zero)
Post by: SkiesAhoy on March 07, 2013, 11:33:38 PM
10 month old necro. I will hurt someone, by God.

(http://www.novarata.net/thread_necromancer_0.jpg)

Locked.
SimplePortal 2.3.5 © 2008-2012, SimplePortal