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

×

Compliation Error :(

strong textHello. So the following the code which works absolutely fine in netbeans but when I upload on CODECHEF, it shows COMPILATION ERROR. Plz help. I want to know where am I wrong while copying the code so that I can amend it and go for further codes.

import java.util.Scanner; public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int l,b;
System.out.println("Enter length and breadth: ");
l=in.nextInt();
b=in.nextInt();
float area, peri;
area = l*b;
peri = 2*(l+b);
if(area>peri){
    System.out.println("Area");
    System.out.println("Area="+area);
}
else
    System.out.println("Perimeter");
System.out.println("Perimeter"+peri);

} }

asked 02 Jul '18, 11:48

pari97's gravatar image

0★pari97
32
accept rate: 0%

converted to question 02 Jul '18, 11:51


I think there is an error in

public class Main()

If it is public, then the class name has to be codechef else don't make it public.

Secondly, never use extra output statements, such as "Enter length and breadth: " as it will give WA on submitting.

Make sure that the output matches exactly with the sample output.

link

answered 02 Jul '18, 14:00

arnavvarshney's gravatar image

3★arnavvarshney
1548
accept rate: 9%

Please upvote and accept the answer, if it solved your doubt!

(02 Jul '18, 21:40) arnavvarshney3★

thank you. It was really helpful. I really appreciate your help.

(03 Jul '18, 00:20) pari970★

Sorry to trouble again, but this time I *uploaded with Scanner in = new Scanner(); and it showed wrong. without scanner also it shows compilation error. :( what should i write/change?

class Main {

public static void main(String[] args) {

int l,b;

float area, peri; area = lb; peri = 2(l+b); if(area>peri){ System.out.println("area"); System.out.println(area); } else System.out.println("Peri");
System.out.println(+peri); } }

(03 Jul '18, 00:31) pari970★

https://www.codechef.com/viewsolution/19057232

Check this out! I hope it will solve all your doubts! Scanner in = new Scanner(System.in) is required!

Also note that area and perimeter would be integers and not float given that L, B are integers.

I also changed the data type of L, B to long, just as a precaution, as for large inputs of L, B, they might overflow! (Not necessary)!

(03 Jul '18, 15:29) arnavvarshney3★
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:

×518
×148
×99
×29
×10

question asked: 02 Jul '18, 11:48

question was seen: 139 times

last updated: 03 Jul '18, 15:29