Name-Khushi Mehta Class-10 Section-A Subject-Computer Application School - Mussoorie International School Topic - 20 Programs On Bluej
Name-Khushi Mehta Class-10 Section-A Subject-Computer Application School - Mussoorie International School Topic - 20 Programs On Bluej
CLASS-10
SECTION-A
SUBJECT-COMPUTER Application
OUTPUT:
The sum of first 10 natural numbers is = 55
{
public static void Search(int arr[], int first, int last, int key)
{
int mid = (first + last)/2;
while( first <= last ){
if ( arr[mid] < key ){
first = mid + 1;
}
else if ( arr[mid] == key )
{
System.out.println("Element is found at index: " + mid);
break;
}
else
{
last = mid - 1;
}
mid = (first + last)/2;
}
if ( first > last )
{
System.out.println("Element is not found!");
}
}
public static void main(String args[]){
int arr[] = {10,20,30,40,50};
int key = 30;
int last=arr.length-1;
Search(arr,0,last,key);
}
}
Output:
Element is found at index: 2
temp=n;
while(n>0){
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println("palindrome number ");
else
System.out.println("not palindrome");
}
OUTPUT –
On taking 325 it will show ‘not palindrome’
14) Write a java program to check whether the given
number is a Armstrong number or not.
ANS:
import java.util.Scanner;
import java.lang.Math;
public class armstsrong
{
static boolean isArmstrong(int n)
{
int temp, digits=0, last=0, sum=0;
temp=n;
while(temp>0)
{
temp = temp/10;
digits++;
}
temp = n;
while(temp>0)
{
last = temp % 10;
sum += (Math.pow(last, digits));
temp = temp/10;
}
if(n==sum)
return true;
else return false;
}
public static void main(String args[])
{
int num;
Scanner sc= new Scanner(System.in);
System.out.print("Enter the limit: ");
num=sc.nextInt();
System.out.println("Armstrong Number up to "+
num + " are: ");
for(int i=0; i<=num; i++)
if(isArmstrong(i))
System.out.print(i+ ", ");
}
}
Output:
Armstrong Number up to 211 are:
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153,
OUTPUT:
673: Six Hundred Seventy Three
85: Eighty Five
Output:
Not Automorphic
Not Automorphic
if (peterson(n))
System.out.println("Yes");
else
System.out.println("No");
}
}
Output:
Yes
x-----x-----x-----x-----x-----x-----x-----x-----x-----x-----x-----
x-----x-----x-----x-----x-----x-----x-----x-----x-----x-----x-----
x-----x-----x-----x-----x-----x
THANK YOU