You are on page 1of 5

LOGIC FOR THE ASSIGNMENT PROBLEMS

1. Check whether the given character is Vowel or Consonant? a. Enter the character. b. Compare entered character with vowels (a, e, i, o and u). (if ch==a or ch==e) c. Condition is true then given character is vowels d. If condition is false then given character is consonant. 2. Find the Area and Perimeter of Circle? a. As we know the formula of Area and Perimeter of Circle. b. Area = PI * Radius * Radius and Perimeter= 2* PI * Radius. c. Take the values of Radius and put the value of radius in formula and get output. 3. Find the factorial of given number? a. Take the input number. b. For Factorial 5 means = 5 * 4 * 3 * 2 * 1. c. So we apply for loop and find factorial of given number. 4. Find the largest number in given three numbers? a. First Check first number with second and third if given number is greater then both then first number is largest b. If first number is not largest then compare second and third number is second is greater than third then second is largest else third number is largest. 5. Write a program to reverse the given number? a. Take a number. b. In loop check whether given number is not equal to zero. i. If true then take remainder in variable by using modulus operator. ii. Then put remainder value in the rev variable by using this statement rev=rev*+remainder iii. Then divide the number by ; number = number/10 c. Print the reverse number.

6. Write a program to swap two numbers. a. Take two number; b. Multiply both number and put into first variable; a=a*b; c. For swap b = a/b; by this statement the value of a will assign to b. d. And a = a/b; by this statement the value of b will assign to a. 7. Write a program to find the LCM and HCF of given two numbers? a. Take two numbers and other three variable like a, b, x, y and temp. b. Assign the value of x to a and value of y to b; a=x and b=y; c. Check in loop that b value Is not equal to 0. i. Temp=b; assign the b value to temp. ii. b=a % b; get the remainder iii. a=temp; assign the temp value of a; d. HCF=a; assign the value to HCF. e. LCM= (x*y)/HCF; for getting LCM we are using this formula. f. Print LCM and HCF Value. 8. WAP to print Floyds triangle. Floyds Triangle means print the following series. 1 23 456 7 8 9 10

a. For this we take a variable num and assign value 1 to it. b. Apply loop for( int i=1; i<=5;i++) i. Apply inner loop for(int j=1;i<=i; j++) 1. Print the value of variable num; 2. Increment the value of num. 3.

9. Check whether given year is leap year or not. a. Take the year variable and enter the year. b. check the condition if((year % 400==0)||(year%4==0 && year%100!=0)) i. true then year is leap year c. else not leap year 10. Addition of matrix. a. Create the three 2 dimension array example int mat1[][]=new int[row][col] b. Take the value from the user using scanner c. For(int i=0;i<row;i++) i. For(int j=0;j<col ;j++) 1. Mat1[row][col]=in.nextInt(); d. Add mat1 and mat2 and assign the value to mat3 i. For(int i=0;i<row;i++) 1. For(j=0;j<col;j++) a. Mat3[i][j]=mat1[i][j]+mat2[i][j]; e. Print the mat3 value. i. For(int i=0;i<row;i++) 1. For(j=0;j<col;j++) a. Print mat3[i][j] 11. Print the prime number between 1 to 100? a. For(int i=1;i<=100;i++) i. Take a boolean variable and assign value true to variable. Boolean isPrime= true ii. For(int j=2;j<i/2;j++) 1. If(i%j==0) a. isPrime=false iii. check if(isPrime) mean if isPrime value is true then print the value of i.

12. WAP to find the largest number in given array of Integer. a. Take an array of Integer with 5 element. b. Take input from user.

c. Assign first value of array to largest variable. Int largest=arr[0] d. Apply loop to find the largest element i. For(int i=0;i<arr.length;i++) 1. If(largest<arr[i]) a. Largest=a[i] e. Print the largest value. 13. WAP to sort the array element in ascending array. a. Take an array element and insert the value in array. b. Print the array value before the sorting. c. Apply loop for sorting i. For(int i=0;i<arr.length;i++) 1. For(int j=i+1;j<arr.length;j++) a. If(a[i]>a[j]) i. Int temp=arr[i]; ii. arr[i]=arr[j]; iii. arr[j]=temp; ii. Print the sorted array. 14. Count the number of character in Given String? a. Take a String variable and assign the value to String variable. b. Call the method of String class length (); int len=str.length ();//this method will give length of String. c. Print the value of len the will give the number of character in give String. 15. WAP to sum of individual digit in the given number? a. Take variable rev=0, rem=0,sum=0,num and all are integer type. b. Take the number from the user in num variable. c. Apply loop till number not equal to 0. i. rem=num%10; ii. sum=sum+rem; iii. num=num/10; d. print the sum.

16. Check whether given number is palindrome or not? a. Apply the reverse number program logic. b. Check whether given number is equal to rev or not. i. If true then print given number is palindrome. ii. Else not palindrome. 17. Check whether given number is prime of not? a. Take a number. b. Declare a Boolean variable boolean isPrime=true; c. Apply loop and check for(int i=2;i<=n/2;i++) i. if (n%i==0) check whether n is divide by I and gives remainder is zero or not. 1. If remainder is zero then boolean variable isPrime = false; d. Check if(isPrime) means the value of isPrime is true or false i. If true then given number is Prime ii. Else given number is not prime.

You might also like