0
Paint Costs || Java | What did i wrong?
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); int totalColor = input.nextInt(); double canvasAndBrushes = 40.0; double purchase = canvasAndBrushes + totalColor; double finishedPurcase = purchase *110/100; System.out.println(finishedPurcase ); } }
17 ответов
+ 2
import java.util.*;
public class Program
{
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int n=sc.nextInt();//20
double p=5*n+40;//here each colour costs Rs.5 so number of colours*5+additional charges for canvas and brushes(40)
int r=(int)(Math.rint (p+(10*p/100)));//here 10%tax is collected and round off function is used so that it should give the floor values of decimals
System.out.println(r);
}
}
+ 1
you did everything right, but he will not appreciate it and will not remember it. it is much more useful to push for a solution than to give a ready-made one. what do you think, if you are a fisherman and know how to fish. a hungry man will approach you and ask you to feed him. what's better in the long run? give him a fish or teach him how to fish?
+ 1
better tell us how to convert float to int, since the program will not pass the test
+ 1
"Tell me and I forget, teach me and I remember, involve me and I learn"
- Benjamin Franklin
+ 1
Because test cases require to be in integers
0
Hi! you made a slight mistake in the first formula. explain how you calculate the total cost? brushes and colors? Hint question: how much does one color cost?
0
Atul, I asked you not to give direct answers, you are thus disrupting the learning process
0
Ярослав Вернигора(Yaroslav Vernigora) Sorry as he showed his attempt and tried to accomplish his work so I helped him a bit because he was missing one mathematical function only. I beg your pardon if any wrong I did
0
Why float to int?
0
because you won't pass the tests. you will have the result with a decimal part. and the answer must be a whole. do you know how to do this? and you found your mistake in the formula?
0
So I solved the main problem. But test case 3 and 4 are almost hidden.
import java.util.Scanner;
public class LearningJava {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int colors = scanner.nextInt();
int costs = (40 + 5 * colors);
int tax = costs*10/100;
int cost = tax + costs;
System.out.println(cost);
}
}
0
most likely, the data should be float, but the final result, according to the conditions of the problem, should be rounded to the nearest integer. make all the values float (so that there is something to round). round the final result to the nearest integer
0
First do all tasks in double or float but atlast round of it ceiling value
0
Thank you. It worked. But can you explain me more exact, why float and not int?
0
Hope this helps you
0
Bcoz rezult must be rounded to the nearest int
0
"Output Format
A number that represents the cost of your purchase rounded up to the nearest whole number."