Importantforhalfyearly
Importantforhalfyearly
{
static void main()
{
short n;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter a number:”);
n=sc.nextShort();
if(n%2==0)
System.out.println(“Even”);
else
System.out.println(“Odd”);
}
}
(for parametrer)
(Write a program to check whether an int type number (taken as input) is a 3-digit
number
divisible by three or not.)
(for triangle)
int n,f,l,s,p;
Scanner sc=new Scanner(System.in);
System.out.println(“Enter an integer:”);
n=sc.nextInt();
if (n>=10 && n<=99)
{
f=n/10;
l=n%10;
s=f+l;
p=f*l;
if (s+p==n)
System.out.println(“Special 2-digit number”);
else
System.out.println(“Not a special 2-digit number”);
}
else
System.out.println(“Not a 2 digit number”);
A special two-digit number is such that when the sum of its digits is added to the
product of
its digits, the result is equal to the original two-digit number.
System.out.println((n>0)?“Positive”:(n<0)?“Negative”:“Zero”);
(+ve, -ve, 0)
case 10:
case 100:
System.out.println(“Ten and hundred”);
break;
case 1000:
case 400:
System.out.println(“Thousand and 4 hundred”);
(when doing more than 1 case at once)
if(n%9==1)
System.out.println(“Magic number”);
else
System.out.println(“Not a magic number”);
}
}
(for magic no)