CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
Divakar Reddy
Level 15
Nandyal
  • 01.07.2019
  • 856views
  • 2comments

whats wrong in my code , last condition was not satisfied by the compiler . can anyone help me this

Question about the task Boss, something weird is happening
Java Syntax,  Level 5,  Lesson 12
Under discussion

Task: The program reads two numbers from the keyboard and displays their sum on the screen.

Requirements:
  • The program should read the numbers from the keyboard.
  • There must be only one main method in the class.
  • The program should display a string that starts with "Sum = ".
  • The program should display a string that ends with the sum of the entered numbers.
package com.codegym.task.task05.task0530; import java.io.*; /* Boss, something weird is happening */ public class Solution { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String num1=reader.readLine(); String num2=reader.readLine(); int a = Integer.parseInt(num1); int b=Integer.parseInt(num1); int sum = a + b; System.out.println("Sum = " + sum+" the sum of the entered numbers."); } }
0
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Kuldeep Mangrola
Level 8 , Ahmedabad, India
2 July 2019, 08:23
line = 16 you storing num1 instead of num2 && line = 19 System.out.println("Sum = " + sum); only display the result this way don't write extra string like " the sum of the entered numbers."
0
MBC
Level 14 , Apeldoorn, Netherlands
1 July 2019, 14:25
You are reading in num1 into both integer inputs, instead of num1 for the first input and num2 for the second one. So change it to
String num1=reader.readLine();
        String num2=reader.readLine();
        int a = Integer.parseInt(num1);
        int b=Integer.parseInt(num2);
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • 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 Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.