Computer Science 11TH Record
Computer Science 11TH Record
RECORD
2024 - 25
SANJAY K
XI A
Roll No. 27
Program 1
AIM : Define a class to accept a number and check if
it is a superspy or not. In a Superspy : No. of digits =
Sum of digits
Algorithm : Accept a number. Split the digits and
add them. Count the number of digits. Check if they
are equal.
SOURCE CODE:
import java.util.*;
public class superspy_Rec1
{
public static void main ( String args[]){
Scanner sc = new Scanner(System.in);
int digits,num,counter=0,sum=0;
boolean superspy=false;
System.out.println("ENTER A NUMBER TO CHECK IF IT IS A
SUPER SPY OR NOT");
num=sc.nextInt(); // entering number
while(num>0){
counter++; //counting digits
digits = num%10;
sum = sum + digits; //finding sum of digits
num=num/10;
}
if(counter==sum) //checking with condition
superspy=true;
else
superspy=false;
superspy_Rec1 obj = new superspy_Rec1();
obj.check(superspy); //calling the method to display
}
public void check( boolean supspy ){
if (supspy == true )
System.out.println("The entered number is a Superspy");
else
System.out.println("The entered number is not Superspy");
}
}
1
INPUT / OUTPUT:
2
Program 2
AIM : To check a positive integer if it is a Haming number and
display the result in the format given below :
3600= 2x2x2x2x3x3x5x5
Program should display error if negative number is entered.
Haming numbers only prime factors are 2 , 3 or 5.
SOURCE CODE:
import java.util.*;
public class HamingNumber_Rec2
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
HamingNumber_Rec2 obj = new HamingNumber_Rec2();
int a = sc.nextInt(); //accepting a number
boolean ifprime;
System.out.println("Enter a positive integer to check Haming number");
if(a<0)
System.out.println("ERROR : The number is negative"); // error message
else{
System.out.print( a + " " + "=" +"");
for(int i = 1 ; i<=a ; i++)
{
if (a%i==0)
{
ifprime= obj.checkprime(i);
if( ifprime==true)
{
while(a%i==0){
if( i==2 ){
System.out.print(i + "x"); //checking if the prime factor is 2
a=a/2;
}
if(i==3){
System.out.print(i + "x"); //checking if the prime factor is 3
a=a/3;
}
if(i==5){
System.out.print(i + "x"); //checking if the prime factor is 5
a=a/5;}
}
}}
}
3
}
System.out.println("its a Haming number");
}
INPUT / OUTPUT:
4
Program 3
AIM : To convert a binary number to decimal and a decimal number
to a binary number
Algorithm: DECIMAL TO BINARY : Accept a number. Find the
reminders on dividing by 2 and concat it . Reverse the string and add
“1” to the start of string.
BINARY TO DECIMAL : Accept a number. Split the digit and multiply
with 2 raised to powers going till max digits and add them.
SOURCE CODE:
iimport java.util.*;
public class BINARYDECIMAL_Rec3
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number to convert from decimal to binary");
int n = sc.nextInt(); //number to convert from decimal to binary
String newnum = "";
while (n>1){
int rem = n%2;
newnum = newnum + rem; //splitting the reminders and concatting
n=n/2;}
String newstr="";
for (int i = newnum.length()-1 ; i>= 0 ; i--)
{
newstr = newstr + newnum.charAt(i); // reversing the string
}
System.out.println("1"+newstr); //adding 1 infront of the string
System.out.println("Enter a number to convert from binary to decimal");
int bin = sc.nextInt(); // number to convert from binary to decimal
BINARYDECIMAL_Rec3 obj = new BINARYDECIMAL_Rec3();
obj.decimal(bin); // calling the method
}
public void decimal(int d)
{
double num =0;
for(int i=0;d>0;i++)
{
num = num + (d%10) * Math.pow(2,i); //multiplying with 2 raised to power and
adding the number
d = d/10;
}
System.out.print(num);
}
} 5
INPUT / OUTPUT:
6
Program 4
AIM : Write a program to accept an even integer n and find all the
odd prime pairs.
SOURCE CODE:
import java.util.*;
public class Goldback_rec4
{
public static void main(String arg[])
{
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
Goldback_rec4 obj = new Goldback_rec4();
if(a%2!=0 || a<0)
{
System.out.println(" Enter an even positive interger");
a = obj.input();
}
for(int i =2;i<a/2;i++)
{
if(obj.prime(i)==true&& obj.prime(a-i)==true) // checking if sum of two odd primes is that number
{
System.out.println("("+i+","+(a-i)+")");
}
}
}
public int input()
{
System.out.println("enter:");
7
INPUT / OUTPUT:
8
Program 5
AIM : To check if it is a evil number or not. Evil number has even number of 1s in
its binary equivalent.
Algorithm: Accept a number and convert it to its binary form. Split the digits
from the binary number and check the frequency of 1 in that . If the frequency
leaves a reminder of 0 when divided by 2 (i.e. its even) then it is an evil number.
SOURCE CODE:
import java.util.Scanner;
public class Rec5_Evilnum
{
public static void main(String args[]) {
Scanner sc= new Scanner(System.in);
System.out.print("Enter a positive number: ");
int n = sc.nextInt(); //accepting a number
if (n < 0) {
System.out.println("Invalid Input"); //checking if positive
return;
}
int count = 0;
int pow = 0;
int binNum = 0;
while (n > 0) {
int d = n % 2;
if (d == 1)
count++; //counting the number of 1s appearing
binNum += (int)(d * Math.pow(10, pow)); //converting it to binary number
pow++;
n /= 2;
}
System.out.println("Binary number:" + binNum);
System.out.println("No. of 1's: " + count);
if (count % 2 == 0) //checking if number of 1s is even
System.out.println("It is an Evil Number");
else
System.out.println("It is Not an Evil Number");
}
}
9
INPUT / OUTPUT:
10
Program 6
AIM : Program to determine how many unique digit integers
are there in the range between m and n and output them.
Algorithm: Accept Two limits. Convert the number to string
and check if the all adjacent characters are repeating. If
repeating they are not unique else print the number
SOURCE CODE:
import java.util.*;
public class Rec6_unique
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter two values less than 30000 where m<n");
System.out.print("Enter m");
int m = sc.nextInt(); //acceoting limits
System.out.print("Enter n");
int n = sc.nextInt(); //accepting limits
int z=0;
System.out.print("The unique numbers are: ");
for (int i = m+1; i < n;i++){
String a = ""+i;
boolean unique = true;
for (int k = 0; k < a.length() - 1; k++) {
for (int j = k + 1; j < a.length(); j++) {
if (a.charAt(k) == a.charAt(j)) { // if a character is repeating then it is not
unique
unique = false;
}
}
}
if (unique) {
z++; // counting the number of unique numbers
System.out.print(i+", "); //printing the numbers
}
}
System.out.println();
System.out.println("The number of unique numbers are: " + z);
}
} 11
INPUT / OUTPUT:
12