Welcome, Guest. Please login or register.

Author Topic: [Java] Number Evaluator (Positive, negative, zero)  (Read 4229 times)

0 Members and 1 Guest are viewing this topic.

Offline Mr. Commodore

[Java] Number Evaluator (Positive, negative, zero)
« 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...
« Last Edit: May 05, 2012, 06:55:13 AM by Mr. Commodore »

Offline Blackllama

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #1 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)

Conjoint Gaming [Game On]

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #1 on: May 05, 2012, 06:36:56 AM »

Offline Mr. Commodore

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #2 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.

Offline Zukuto

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #3 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:


Offline Mr. Commodore

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #4 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.

Offline Blackllama

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #5 on: May 06, 2012, 12:21:07 AM »
Dude, get eclipse.

Offline Sprite

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #6 on: May 06, 2012, 12:53:45 AM »
Ya really why are you using Dr. Java eclipse is 100 times better



Offline Mr. Commodore

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #7 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.

Offline TRMayhem

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #8 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.

Offline Blackllama

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #9 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.

SkiesAhoy

  • Guest
Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #10 on: March 07, 2013, 11:33:38 PM »
10 month old necro. I will hurt someone, by God.



Locked.

Conjoint Gaming [Game On]

Re: [Java] Number Evaluator (Positive, negative, zero)
« Reply #10 on: March 07, 2013, 11:33:38 PM »

 


* ShoutBox!

Refresh History

SimplePortal 2.3.5 © 2008-2012, SimplePortal