+ 2

This code is giving expected output but this code not passing the test cases in code coaches(Mathematics-hard)

https://code.sololearn.com/cU188nb8n99y/?ref=app

21st Apr 2023, 3:04 PM
Kailash Yandrapu
4 Answers
+ 2
Oscar Panuko but the two private test cases are failing i do not know why
22nd Apr 2023, 1:09 AM
Kailash Yandrapu
+ 1
The task has 2 inputs in separate lines. But your code reads input of single line. For first input, Read line as text and convert to integer..
21st Apr 2023, 6:51 PM
Jayakrishna 🇼🇳
+ 1
When you take INT input you need to call sc.nextLine(); right after because the end of line is not stored in INT variable the second call sc.nextLine(); will have the end of line not the String input. Your Code doesn't pass all cases the problem says it could have multiple operations i'm guessing like (12+3*6) so you must do multiplication first then sum I did this in order to verify you got the correct input and still doesn't pass all cases import java.util.*; public class Program { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int y=0,t=0; String a1=""; sc.nextLine(); <————— String b=sc.nextLine(); String d=b.trim(); String c[]=d.split(" "); int c1[]=new int[c.length]; ........ }
22nd Apr 2023, 12:02 AM
Oscar Panuko
Oscar Panuko - avatar
+ 1
Kailash Yandrapu The previous answers do explain why. Pls read them carefully.
22nd Apr 2023, 2:57 AM
Emerson Prado
Emerson Prado - avatar