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

×

FLOW001:Addition of two numbers

// can anyone please tel me whats wrong in this answer

import java.util.Scanner; public class useradd{ public static void main (String []args){

int result;
Scanner scan =new Scanner (System.in);
int a= scan.nextInt();
int b= scan.nextInt();
int T=scan.nextInt();
if (T<1000){
if (a<10000){

if (b<10000){


    result  = a+b;

    System.out.println (result);
    }
    }

} System.out.println ("user input addition is conpleted"); }

}

asked 16 Sep '17, 15:28

vinay_4275's gravatar image

0★vinay_4275
1
accept rate: 0%


You should read "how to get started" with Codechef. Link is given on Practice page. By the way, Here T is no of test cases that means you have to answer T times so you should use a loop that runs T times. And again see the output format. Every time you should print the sum in new line. And don't print anything extra that will lead to a wrong answer. In your case, printing "user input addition is conpleted" is not expected. So remove that line. Another mistake is, you are scanning a then b then T. But see the input format, First T is given, Then T times, a and b are given.
So what you need is
1) Scan T
2) Put a loop for T test cases
3) Read a and b for each iteration of loop
4) Print the sum and go to next line
5) Remove System.out.println("user input addition is conpleted");
I hope this helps!!!

link

answered 16 Sep '17, 15:48

vichitr's gravatar image

5★vichitr
2555
accept rate: 11%

// can anyone tell me what is wrong here. import java.util.; import java.lang.; import java.io.*;

/ Name of the class has to be "Main" only if the class is public. / class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); if(t>=1&&t<=1000) { for(int i=1;i<=t;i++) {
int sum; int a=sc.nextInt(); int b=sc.nextInt(); if(a>=1 &&a<=10000 && b>=1 && b<=10000) { sum=a+b; System.out.println(sum); } }

}

}

link

answered 09 Nov '17, 11:10

amruta1991's gravatar image

0★amruta1991
1
accept rate: 0%

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,302

question asked: 16 Sep '17, 15:28

question was seen: 471 times

last updated: 09 Nov '17, 11:10