atm problem

import java.io.BufferedReader;
import java.io.InputStreamReader;

class checkFloat
{
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		try
		{
			
		
		float n=Float.parseFloat(br.readLine());
				
			float x=Float.parseFloat(br.readLine());
			
					
			if(n%5!=0)
			{
				System.out.println(x);
				return;
				}
		if(x>=0.5+n)
		{
			
			float z=x-n;
			z-=0.5;
				System.out.println(z);
			
		}
		else
		{
			
				System.out.println(x);
		}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
		
}
************************************************************************

import java.io.BufferedReader;
import java.io.InputStreamReader;

class checkFloat
{
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		try
		{
			
		
		float n=Float.parseFloat(br.readLine());
				if(n<=0)
				return;
			else if(n>2000)
					return;
			float x=Float.parseFloat(br.readLine());
			if(x<0)
				return;
			else if(x>2000)
					return;
					
			if(n%5!=0)
			{
				System.out.println(x);
				return;
				}
		if(x>=0.5+n)
		{
			
			float z=x-n;
			z-=0.5;
				System.out.println(z);
			
		}
		else
		{
			
				System.out.println(x);
		}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
		
}

I tried both of them…it is giving wrong answer…why?

Hi @urvi_7! When dealing with Java, you have to name your class as “Main” (according to answer to FAQs). Also, you don’t have to print out any kind of extra stuff like you are handling exception here and calling print Stack trace. Also, be very careful about the output format. You can read more guidelines here : FAQ | CodeChef

its not neccessary to make our class name Main.you can name any

@saket can u then tell me wats the problm wth ma code then

I think you are not taking the input correctly

The inputs are in same line (eg 30 120 not 30 \n 120)

use this set of code to take input
String in[]=br.readLine().split(" ");
float n=Float.parseFloat(in[0]);
float x=Float.parseFloat(in[1]);

What was your problem statement?

it is saying wrong answer…i changed my code…but still the same problem…wrong answer :frowning:


import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		try
		{
			
		
		float n=Float.parseFloat(br.readLine());
				
			float x=Float.parseFloat(br.readLine());
		
					
		
		if((n%5!=0)||(x<(n+0.50)))
		{
			
				System.out.println(x);
		}
		else
		{
				System.out.println(x-n-0.50);
			
		}
		}
		catch(Exception e)
		{
		e.printStackTrace();
      }finally{
        br.close();
      }
	}
		
}