Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Tcs nqt 2019 p 1
1. Coding in JAVA
TCS NQT 2019
By
PHANEENDRA BOLLA
(Bachelor of Technology)
In
Computer Science and Engineering
2. Write a program to find out the given year is leap year or not.
If the given input is leap year print 1 else print 0.
Input – 2048
Output - 1
• Algorithm
Step 1:
read input n from the user;
Step 2:
if n is divisible by either 4 or 400 and the remainder is 0 then,
print 1;
else
print 0;
3. Program in java
import java.util.*;
class LeapOrNot
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
int n= sc.nextInt();
LeapOrNot lp= new LeapOrNot();
int res=lp.leap(n);
System.out.println(res);
}
int leap(int n)
{
if(n%400==0||n%4==0)
return 1;
else
return 0;
}
}