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/Can anyone instruct me how to solve it ?
Ashok Rai
Level 3
Kathmandu
  • 05.12.2018
  • 2549views
  • 4comments

Can anyone instruct me how to solve it ?

Question about the task Task with percentages
Java Syntax,  Level 3,  Lesson 3
Under discussion


Write the code for the addTenPercent method, which increases the passed integer by 10%.
Use the return statement to return the result from the addTenPercent method.

Consider this example:
return 123 * 435;

Requirements:
  • The addTenPercent method should increase the passed number by 10% percent.
  • The main method should call the addTenPercent method.
  • The main method should display the results of the call.
  • The addTenPercent method should not display anything.
package com.codegym.task.task03.task0304; /* Task with percentages */ public class Solution { public static double addTenPercent(int i) { //write your code her double tenpercent = (100 / 10) * (1 / 9) ; // System.out.println(tenpercent); return (i + tenpercent); } public static void main(String[] args) { System.out.println(addTenPercent(9)); } }
0
Comments (4)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Venkatesh RM
Level 16 , Bangalore, India
13 January 2020, 17:22
double d = i + (i * (0.1)); return d;
+2
Ravikumar R S
Level 4 , Bengaluru, India
21 February 2019, 09:12
return i * 1.1;
+3
Khurram
Level 16 , Lahore, Pakistan
7 December 2018, 05:55
the addTenPercent method should increase the value of anything that is passed to it by 10% 1. you have hard coded the value 9 in line 11, you should use the variable ' i ' 2. in line 11, integers are used for the operation but the answer is stored in a double, the program will perform the operation but will store the answer without the decimal part in the double variable 3. even after adjusting the operators to be double, the formula used is incorrect, it converts 9 to 10.11.., the answer here should be 9.9
+1
Guadalupe Gagnon
Level 37 , Tampa, United States
5 December 2018, 16:43
The correct output to the method should be 9.9 when passed 9 as an argument. Your code spits out 9. The problem is that you are using integers in your calculation instead of doubles. The number is cast to a double after the calculation completes. to fix this try using numbers that include a decimal and a zero (Ex: 10.0 instead of 10). The compiler will recognize the numbers as doubles and correctly calculate fractions of whole numbers then. You still have a math error to figure out, as your code prints out 10.1111111 after applying this. A couple correct formulas to apply (choose one) are: number + (number * 10%) or number * 110%
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 © 2025 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2025 CodeGym