0% found this document useful (0 votes)
17 views4 pages

Importantforhalfyearly

hii

Uploaded by

parthalaha852
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views4 pages

Importantforhalfyearly

hii

Uploaded by

parthalaha852
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

7.

The following is a segment of a program:


x=1; y=1;
if(n>0)
{
7. The following is a segment of a program:
x=1; y=1;
if(n>0)
{

{
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)

if((n>=100 && n<=999 || n>=-999 && n<=-100) && n%3==0)

(Write a program to check whether an int type number (taken as input) is a 3-digit
number
divisible by three or not.)

Write a program to pass 2 integer numbers as parameters. If either of the two


numbers is 0,
display invalid entry and the program should end, if it is valid entry, divide the
larger number
with the smaller number and display the result.
Ans.
class Q13
{
static void main(int a, int b)
{
float c;
if (a==0 || b==0)
System.out.println(“Invalid entry”);
else
{
if(a>b)
c=(float)a/b;
else
c=(float)b/a;
System.out.println(“Quotient:”+c);
}
}
}

if(a<b+c && b<c+a & c<a+b)


{
if(a*a<b*b+c*c && b*b<c*c+a*a && c*c<a*a+b*b)
System.out.println(“Acute angled triangle”);
else if(a*a>b*b+c*c || b*b>c*c+a*a || c*c>a*a+b*b)
System.out.println(“Obtuse angled triangle”);
else
System.out.println(“Right angled triangle”);
}
else
System.out.println(“Does not form a triangle”);

(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)

keep default at the last of tarnary***********

System.out.println(“Enter a number in the range 1-12:”);


switch(n%3)
{
case 0:
System.out.println(“Divisible by 3”);
break;
default:
System.out.println(“Not divisible by 3”);
(to check divisibility without if else)

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)

if (a*a==b*b+c*c || b*b==a*a+c*c || c*c==a*a+b*b)


System.out.println(“Pythagorean Triplet”);
else
System.out.println(“Not a Pythagorean triplet”);
}
}
(to check pythogorian triplet)

System.out.println(“Enter the 3 sides of the triangle:”);


a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
if (a<b+c && b<c+a && c<a+b)
{
if (a==b && b==c)
ar=Math.sqrt(3)/2*a*a;
else if(a*a==b*b +c*c)
ar=1/2.0*(b*c);
else if(b*b==a*a +c*c)
ar=1/2.0*(a*c);
else if(c*c==b*b +a*a)
ar=1/2.0*(b*a);
else
{
s=(a+b+c)/2.0;
ar=Math.sqrt(s*(s-a)*(s-b)*(s-c));
}
System.out.println(“Area=”+ar);
}
else
System.out.println(“A triangle cannot be formed”);
}
}
(triangle area)

You might also like