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

×

why this java code is showing a runtime error.

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

chefkp3006's gravatar image

2★chefkp3006
12
accept rate: 0%

edited 24 Mar '14, 20:42

vermashubhang's gravatar image

5★vermashubhang
1.5k11025


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.

link

answered 24 Mar '14, 20:49

vermashubhang's gravatar image

5★vermashubhang
1.5k11025
accept rate: 23%

edited 24 Mar '14, 20:58

Its not any compulsion of having class name as Main on Codechef.

(24 Mar '14, 21:06) vinayawsm4★

@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) vinayawsm4★

You are taking the inputs in reverse order. You need to input amt first and then bal. You need not make the class public.

link

answered 24 Mar '14, 21:03

vinayawsm's gravatar image

4★vinayawsm
1.9k21430
accept rate: 24%

toggle preview
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