You are not logged in. Please login at www.codechef.com to post your questions!

×

# why this java code is showing a runtime error.

 0 import java.util.Scanner; public class ATM{ public static void main(String[] args){ Scanner ip = new Scanner(System.in); double bal = ip.nextDouble(); int amt = ip.nextInt(); if((bal>=0&&bal<=2000)&&(amt>0&&amt<=2000)){ if((bal>amt+0.5)&&(amt%5==0)){ bal-=(amt+0.5); System.out.println(bal);} else System.out.println(bal); } } }  RESULT : RUNTIME ERROR Doubt ; Y is it so? it is working on pc asked 24 Mar '14, 20:24 1●2 accept rate: 0% 1.5k●1●10●25

 0 The name of the class should be Main in java for all the submissions on CodeChef. Rename it to Main. Please don't try different programming languages if it's not getting accepted in one language. Try debugging the error to check for mistakes. answered 24 Mar '14, 20:49 1.5k●1●10●25 accept rate: 23% Its not any compulsion of having class name as Main on Codechef. (24 Mar '14, 21:06) @vinayawsm...if u declare the class as public...then it is a compulsion!!! (24 Mar '14, 21:12) kunal3614★ okey. I am sorry I didn't know that. (24 Mar '14, 21:14)
 0 You are taking the inputs in reverse order. You need to input amt first and then bal. You need not make the class public. answered 24 Mar '14, 21:03 1.9k●2●14●30 accept rate: 24%
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• link:[text](http://url.com/ "title")
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,133
×227
×177
×29

question asked: 24 Mar '14, 20:24

question was seen: 963 times

last updated: 24 Mar '14, 21:14