Length and breadth of a rectangle are 5 and 7 respectively. Write a program to calculate the area and perimeter of the rectangle.
classAns{publicstaticvoidmain(String[]args){intx=5inty=7System.out.println("Area is "+(5*7)+"\nPerimeter is "+(2*(5+7)));}}
2.
Write a program to calculate the perimeter of a triangle having sides of length 2,3 and 5 units.
3.
Write a program to add 8 to the number 2345 and then divide it by 3. Now, the modulus of the quotient is taken with 5 and then multiply the resultant value by 5. Display the final result.
If the marks of Robert in three subjects are 78,45 and 62 respectively (each out of 100 ), write a program to calculate his total marks and percentage marks.
10.
Suppose the values of variables 'a' and 'b' are 6 and 8 respecrtively, write two programs to swap the values of the two variables.
1 - first program by using a third variable
2 - second program without using any third variable
( Swapping means interchanging the values of the two variables E.g.- If entered value of x is 5 and y is 10 then after swapping the value of x and y should become 10 and 5 respectively.)
classAns{publicstaticvoidmain(String[]args){//using third variable//a = c//a = b//b = c//without using third variable//b = b-a//a = b+a//b = -(b-a)}}
11.
Write a program to convert Fahrenheit into Celsius.
12.
The total number of students in a class are 90 out of which 45 are boys. If 50% of the total students secured grade 'A' out of which 20 are boys, then write a program to calculate the total number of girls getting grade 'A'.
13.
Write a program to calculate the sum of the first and the second last digit of a 5 digit. E.g.- NUMBER : 12345 OUTPUT : 1+4=5
classAns{publicstaticvoidmain(String[]args){intn,first,second,third,forth,fifth,sum;n=23462;/*Now we will take out each digit of this number and then finally add the first and the second last digits*/first=n/10000;//first digitn=n%10000;second=n/1000;//second digitn=n%1000;third=n/100;//third digitn=n%100;forth=n/10;//forth digitfifth=n%10;//fifth digitsum=first+forth;System.out.println("sum : "+sum);}}
14.
Take a 4 digit number. Write a program to display a number whose digits are 2 greater than the corresponding digits of the number TAKEN.
For example, if the number which was taken is 5696, then the displayed number should be 7818.
15.
Write a program to calculate the sum of the digits of a 3-digit number. Number : 132 Output : 6
16.
Write a program to reverse a 3-digit number. E.g.-Number : 132 Output : 231
classAns{publicstaticvoidmain(String[]args){intn,first,second,third,reverse;/*finding the digits of the entered number n*/n=123;first=n/100;//first digitn=n%100;second=n/10;//second digitthird=n%10;//third digit/*reverse number */reverse=third*100+second*10+first;System.out.println("reverse number : "+reverse);}}