Welcome, Guest. Please login or register.

Author Topic: [Java] Number Evaluator (Positive, negative, zero)  (Read 5230 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
  • Careful what you post. Forum rules still apply in the shoutbox!
  • Pyro: happy birthday Tyber
    July 14, 2024, 01:55:16 PM
  • Finniespin: More of a Patrick Hernandez guy - Born to be Alive
    June 16, 2024, 09:14:27 AM
  • Sly: Aaron Hernandez was a legend of a man
    June 14, 2024, 01:46:02 AM
  • Finniespin: how? what?
    June 01, 2024, 06:28:43 PM
  • Inject OH 4: Lost my discord rip
    May 30, 2024, 12:14:57 AM
  • Finniespin: yoooooooo!
    April 03, 2024, 05:32:48 PM
  • Coreybush11: bump
    April 01, 2024, 10:59:48 PM
  • Finniespin: wut
    March 28, 2024, 05:01:26 PM
  • Inject OH 4: And yes thank you very much Finnie! You are a champion xP
    March 22, 2024, 05:59:12 PM
  • Inject OH 4: Hey abrys agreed we should.
    March 22, 2024, 05:59:02 PM
  • Finniespin: Totally not a spam-bot, also totally not a limited time offer
    March 03, 2024, 05:25:06 PM
  • Finniespin: Anyone looking for a datacenter technician job? We got postings available around US and Europe (EMEA)
    February 17, 2024, 07:23:12 AM
  • Finniespin: https://www.google.com/about/careers/applications/jobs/results/118336179041903302-data-center-technician-global-server-operations
    February 17, 2024, 07:20:25 AM
  • Finniespin: Gave Inject 50 euros to pay for fees ^^
    February 17, 2024, 07:17:42 AM
  • xXArbysOvenMittXx: we gotta get the crew together again one day and hang, add me on discord: ogarbies
    February 12, 2024, 06:52:07 PM
  • xXArbysOvenMittXx: yo who is still paying for this lol
    February 12, 2024, 06:19:47 PM
  • Klondor: wow CG still lives, mind blown
    February 09, 2024, 05:13:53 AM
  • Finniespin: The website is back online!!!
    February 06, 2024, 03:17:05 PM
  • Inject OH 4: xD
    January 14, 2024, 05:55:44 PM
  • Finniespin: Get a load of this guy
    December 16, 2023, 09:16:03 AM
  • Inject OH 4: Sure
    December 09, 2023, 07:22:27 PM
  • HailToTheKing: cum shot . and cum shot. an d cum shot
    December 01, 2023, 01:54:12 PM
  • Finniespin: ffuck
    November 24, 2023, 03:43:47 PM
  • Inject OH 4: ee
    October 12, 2023, 01:13:56 AM
  • Sly: dd
    August 09, 2023, 03:13:48 AM
  • Inject OH 4: cc
    August 03, 2023, 09:51:36 PM
  • Finniespin: bb
    August 02, 2023, 06:12:50 PM
  • Inject OH 4: aa
    July 04, 2023, 10:29:35 PM
  • Shikaru: Been a very long time
    February 20, 2023, 05:42:04 PM
  • Shikaru: Oh wow my account is STILL active :)
    February 20, 2023, 05:42:00 PM
  • Napoleon BonaPARTY: yooo we got a lovense sponsor???
    December 16, 2022, 03:45:43 PM
  • Napoleon BonaPARTY: holy shit
    December 16, 2022, 03:45:24 PM
  • Napoleon BonaPARTY: oh wow its still here
    December 16, 2022, 03:45:21 PM
  • HailToTheKing: legends never die
    October 16, 2022, 01:28:09 PM
  • Live Bait: Oh wow. Still remember my old password.
    September 23, 2022, 08:37:38 AM
  • Mr_Rainbow: Still alive. Hope all is well with everyone this Christmas
    December 09, 2021, 03:31:04 AM
  • SlyWilliam: Much love, from our MC server to our ZPS server <3
    December 07, 2021, 10:23:37 PM
  • SlyWilliam: For the record, I don't REALLY remember all of you, but goddamn do I MISS all of you <3
    December 07, 2021, 10:23:10 PM
  • Pyro: parrot
    September 07, 2021, 05:23:18 AM
  • Inject OH 4: Do you mean for people that haven't come on in a long time and have to reagree?
    August 02, 2021, 11:39:42 PM

SimplePortal 2.3.5 © 2008-2012, SimplePortal