I still fail many of the tests.Could anyone explain me why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I still fail many of the tests.Could anyone explain me why?

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str=sc.nextLine(); String[]s1=str.split(","); double g2=Integer.parseInt(s1[1]); double g3=Integer.parseInt(s1[2]); double co=g2+g3; double res=((co)+co*0.07)*0.3; System.out.println((int)Math.floor(res)); } }

15th Dec 2022, 2:10 PM
Killiam Chances
Killiam Chances - avatar
4 Answers
+ 2
Can you post what the task is? Why do you do the parsing instead of taking the input as the correct variable type?
15th Dec 2022, 2:15 PM
Ausgrindtube
Ausgrindtube - avatar
+ 2
// Change the index to 0,1 instead of 1,2 double g2=Integer.parseInt(s1[0]); // first index double g3=Integer.parseInt(s1[1]); // second index
15th Dec 2022, 2:43 PM
SoloProg
SoloProg - avatar
+ 1
Killiam Chances , Hope this code helps Scanner input = new Scanner(System.in); String[] a = input.nextLine().split(","); double[] lst = Arrays.stream(a).mapToDouble(num -> Double.parseDouble(num)).toArray(); Arrays.sort(lst); lst = Arrays.copyOfRange(lst, 0, lst.length-1); double t=0, tx=1.07, d=.3; for (double x : lst) t += (x*tx)*d; System.out.println((int)t); https://code.sololearn.com/ceY6T79Vko74
16th Dec 2022, 10:10 AM
SoloProg
SoloProg - avatar
0
Here is the task Your favorite store is having a sale! You pay full price for the most expensive item that you get, but then you get 30% off of everything else in your purchase! How much are you going to save? Sales tax is 7%. Also, you leave anything below a dollar in your saving as a tip to the seller. If your saving is a round amount, you don't leave any tips. Task: Given the prices of items you want to purchase, determine how much you will save during your shopping! Input Format: An string of numbers separated by commas that represent the prices for all of the items that you want to purchase (without tax). Output Format: An integer number that represents the total savings that you got for shopping during the sale. Sample Input: 100.25,80.99,40.00 Sample Output: 38
16th Dec 2022, 8:32 AM
Killiam Chances
Killiam Chances - avatar