CodeGym
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
CodeGym/Help with Java Tasks/whu my code doesnt work in itneleIDE but it works in Ecli...
Albert ENG
Level 6
  • 7/27/22
  • 459views
  • 1comment

whu my code doesnt work in itneleIDE but it works in Eclipse

Question about the task Positive and negative numbers
Java Syntax,  Level 3,  Lesson 10
Under discussion


Use the keyboard to enter three integers. Display the number of positive and negative numbers in the original set in the following form: "Number of negative numbers: a", "Number of positive numbers: b", where a and b are the relevant values.

Examples:
a) if you enter the numbers:
2
5
6

then we display:
Number of negative numbers: 0
Number of positive numbers: 3

b) if you enter the numbers:
-2
-5
6

then we display:
Number of negative numbers: 2
Number of positive numbers: 1

Requirements:
  • The program should read the numbers from the keyboard.
  • The program should display text on the screen.
  • The program should display the number negative numbers in the original set.
  • The program should display the number of positive numbers in the original set.
  • If there are no negative numbers, the program should display "Number of negative numbers: 0".
  • If there are no positive numbers, the program should display "Number of positive numbers: 0".
  • Note that "0" is not a positive or negative number.
package en.codegym.task.jdk13.task04.task0429; import java.io.BufferedReader; import java.io.InputStreamReader; /* Positive and negative numbers */ public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int number1 = Integer.parseInt(reader.readLine()); int number2 = Integer.parseInt(reader.readLine()); int number3 = Integer.parseInt(reader.readLine()); int counter = 0; if (number1 <= -1) {counter ++;} if (number2 <= -1) {counter ++;} if (number3 <= -1) {counter ++;} {System.out.println("Number of negative numbers:" + " " + counter);} if (number1 >= 1) {counter ++;} if (number2 >= 1) {counter ++;} if (number3 >= 1) {counter ++;} {System.out.println("Number of positive numbers:" + " " + counter);} } }
0
Comments (1)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Guadalupe Gagnon
Level 37 , Tampa, United States
27 July 2022, 14:50
What do you mean? Are you asking why the task isn't validating? This is because the output is incorrect. The second example is: -2 -5 6 and the correct output is: Number of negative numbers: 2 Number of positive numbers: 1 Do you mean when you hit the run button it isn't running? This could be because you haven't set up intelliJ with the JDK, or maybe you are running the wrong code, or if you copied and pasted the code into intelliJ from another source then the class, imports, package information would be incorrect. I couldn't make the determination of what the problem is from the information that you gave. If it is running the wrong code, which is a very common user error, then try hitting the green arrow in the line numbers to the left of the main() method (see picture): This will run the current code. IntelliJ is set up to create and build HUGE programs with multiple different entry points. Codegym tasks are one HUGE program where each individual task is an entry point. Because of the intelliJ way intelliJ is designed, when you click the run button at the top of the page it will run the code that it is set to run, which may not be the code you are looking at on your screen. By hitting the green arrow to the left of the main() method you want to run it will run that specific code every time.
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym