0% found this document useful (0 votes)
263 views

Class 11 Computer Science Project ISC Board

The document contains 5 programming questions and their solutions in Java. It includes programs to calculate the sum of two binary numbers, express a number as the sum of consecutive numbers, mix and sort two user-input words, shift the rows of a matrix by a given number of positions, and check if a number is a bouncy number. The document contains the question, sample input/output, and the Java code to solve each problem in under 3 sentences each.

Uploaded by

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

Class 11 Computer Science Project ISC Board

The document contains 5 programming questions and their solutions in Java. It includes programs to calculate the sum of two binary numbers, express a number as the sum of consecutive numbers, mix and sort two user-input words, shift the rows of a matrix by a given number of positions, and check if a number is a bouncy number. The document contains the question, sample input/output, and the Java code to solve each problem in under 3 sentences each.

Uploaded by

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

Computer Science

Name : Abhishek Uttam

Class : 11th

Submitted to : Rishi Sir


I.
Q-1) Write a program to calculate sum of two binary
numbers and print

class BinaryAddition
{
public static void main(String args[])
{
long binary1, binary2;
int i = 0, remainder = 0;
int[] sum = new int[20];
Scanner sc = new Scanner(System.in);
System.out.print("Input first binary number: ");
binary1 = sc.nextLong();
System.out.print("Input second binary number: ");
binary2 = sc.nextLong();
while (binary1 != 0 || binary2 != 0)
{
sum[i++] = (int)((binary1 % 10 + binary2 % 10 + remainder) % 2);
remainder = (int)((binary1 % 10 + binary2 % 10 + remainder) / 2);
binary1 = binary1 / 10;
binary2 = binary2 / 10;
}
if (remainder != 0)
{
sum[i++] = remainder;
}
--i;
System.out.print("Sum of two binary numbers: ");
while (i >= 0)
{
System.out.print(sum[i--]);
}
System.out.print("\n");
}
}

Sample Output

Input first binary number: 1010


Input first binary number: 1111
Sum of two binary numbers: 1101
Q-2) Express a number as sum of consecutive
numbers. (Return-1 if there is no output)

import java.util.*;
class consecutive_num
{
static void number(int lst, int fst)
{
System.out.print(fst++);
for (int x = fst; x<=lst; x++)
System.out.print(" + " + x);
}
static void process(int no)
{
for (int lst = 1; lst < no; lst++)
{
for (int fst = 0; fst < lst; fst++)
{
if(2*no == (lst-fst)*(lst+fst+1))
{
System.out.print(no+ " = ");
number(lst, fst+1);
return;
}
}
}
System.out.print("-1");
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
process(n);
}
}

Sample Output
Q-3)Input two words from user and then mix them and
sort them alphabetically

import java.util.*;
class mixsort
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first word");
String x=sc.next();
System.out.println("Enter the second word");
String y=sc.next();
int k=0;
String s=" ";
if(x.length()>y.length())
{
for(int i=0;i<y.length();i++)
{
s=s+x.charAt(i)+y.charAt(k);
k++;
}
s=s+x.substring(k);
System.out.println("Mixed String-"+s);
}
else
{
for(int i=0;i<x.length();i++)
{
s=s+x.charAt(i)+y.charAt(k);
k++;
}
s=s+y.substring(k);
System.out.println("Mixed String-"+s);
}
char charArray[] = s.toCharArray();
int size = charArray.length;
int temp;
for(int i = 0; i < size; i++ )
{
for(int j = i+1; j < size; j++)
{
if(charArray[i]>charArray[j])
{
temp = charArray[i];
charArray[i] = charArray[j];
charArray[j] = (char) temp;
}
}
}
System.out.print("Sorted Mixed String-");
for(int i = 0; i < size; i++ )
{
System.out.print(charArray[i]);
}
}
}

Sample Output
Q-4)Write a program to shift the rows of matrix:

import java.util.*;
class shift
{
int r,c,s;
int arr[][];
Scanner sc=new Scanner(System.in);
shift(int rr, int cc, int ss)
{
s=ss;
r=rr;
c=cc;
arr=new int[r+1][c];
}
void input()
{
System.out.println("Enter elements of matrix.");
for(int i=1; i<r+1; i++)
{
for(int j=0; j<c; j++)
arr[i][j]=sc.nextInt();
}
}
void process()
{
for(int sh=1; sh<=s; sh++)
{
for(int i=1; i<r+1; i++)
{
for(int j=0; j<c; j++)
arr[i-1][j]=arr[i][j];
}
for(int i=0; i<c; i++)
arr[r][i]=arr[0][i];
}
}
void display()
{
for(int i=1; i<r+1; i++)
{
for(int j=0; j<c; j++)
System.out.print(arr[i][j]+" ");
System.out.println();
}
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number of rows and culoumns of matrix.");
int rr=sc.nextInt();
int cc=sc.nextInt();
System.out.println("Enter no. of rows to be shifted.");
int ss=sc.nextInt();
shift ob=new shift(rr,cc,ss);
ob.input();
System.out.println("Before shifting :");
ob.display();
ob.process();
System.out.println("After shifting :");
ob.display();
}
}
Sample Output
Q-5)Write a program to check whether the number is
Bouncy number or not

import java.util.*;
class bouncy
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int n=sc.nextInt();
int d=String.valueOf(n).length();
int ar[]=new int[d];
int rem=1,j=0;
for(int i=n;i!=0;i/=10)
{
rem=i%10;
ar[j++]=rem;
}
int asc=0,dsc=0;
for(int i=0;i<j-2;i++)
{
if(ar[i]>ar[i+1])
{
asc=1;
}
if(ar[i]<ar[i+1])
{
dsc=1;
}
}
if(asc==0||dsc==0)
{
System.out.println("It is not a bouncy number");
}
else
{
System.out.println("It is a bouncy number");
}
}
}
Sample Output

You might also like