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

Computer Science Project

1. This document contains details about a student named Ayush Kumar's computer science project on programming problems. 2. It lists 15 programming problems and provides sample code solutions for 5 of the problems in Java, including problems to check for prime adam numbers, smith numbers, goldbach numbers, circular prime numbers, and tech numbers. 3. It also includes an acknowledgment section thanking the teacher, principal, parents, and board for their support on the project.

Uploaded by

Ayush Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views

Computer Science Project

1. This document contains details about a student named Ayush Kumar's computer science project on programming problems. 2. It lists 15 programming problems and provides sample code solutions for 5 of the problems in Java, including problems to check for prime adam numbers, smith numbers, goldbach numbers, circular prime numbers, and tech numbers. 3. It also includes an acknowledgment section thanking the teacher, principal, parents, and board for their support on the project.

Uploaded by

Ayush Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 54

NAME: Ayush Kumar

CLASS: 12th UID:


SUBJECT: Computer Science

Serial PROGRAM NAME


1
Number
1 Prime Adam Number
2 Smith Number
3 Goldbach Number
4 Circular Prime Number
5 Tech Number
6 Mirror Matrix
7 Sum of Prime Numbers in an Array
8 Saddle Point
9 Matrix Rotation Column wise in left
10 Magic Square
11 Append, Remove or Insert a string
12 Arranging alphabetically in ascending
order
13 Alphabetically arranged after converting
first and last letter in uppercase
14 Palindrome String
15 Subsets of 3 lettered string

2
ACKNOWLEDGEMENT
I would like to express my gratitude toward to my Computer
teacher Mr. Gagan Dixit for his valuable guidance and nonstop
support during this project. As well as, I am grateful to our
principal Ms. Nandita Basak for providing me with the beautiful
opportunity to work on this Project.
I would also like to thank my parents for encouraging me during
the course of this project.

Finally, I would like to thank the ISC board for giving me this
great opportunity to do this project.

3
1 WRITE A PROGRAM TO CHECK WHETHER THE
ENTERED NUMBER IS PRIME ADAM OR NOT.

import java.util.Scanner;
public class PrimeAdam
{
int reverse(int num)
{ int rev = 0;
while (num != 0)
{ int d = num % 10;
rev = rev * 10 + d;
num /= 10;
}
return rev;
}
boolean isAdam(int num)
{
int sqNum = num * num;
int revNum = reverse(num);
int sqRevNum = revNum * revNum;
int rev = reverse(sqNum);
return rev == sqRevNum;
}

4
boolean isPrime(int num)
{ int c = 0;
for (int i = 1; i <= num; i++)
{ if (num % i == 0)
{ c++;
}
}
return c == 2;
}
void main()
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = sc.nextInt();
boolean adam = isAdam(n);
boolean prime = isPrime(n);
if(adam==true&&prime==true)
System.out.print(n+" is a Prime Adam Number ");
else
System.out.println(n+" is not a Prime Adam Number");
}
}

SAMPLE INPUT 1:
5
Entered number: 13
SAMPLE OUTPUT 1:
13 is a Prime Adam Number

SAMPLE INPUT 2:
Entered number: 24
SAMPLE OUTPUT 2:
24 is not a Prime Adam Number

2 WRITE A PROGRAM TO CHECK WHETHER THE


ENTERED NUMBER IS SMITH NUMBER OR NOT.

import java.util.*;

6
public class SmithNumber_JokeNumber
{
static int findSumPrimeFactors(int n)
{
int i=2, sum=0;
while(n>1)
{
if(n%i==0)
{
sum=sum+findSumOfDigit(i);
n=n/i;
}
else
{
do
{
i++;
}
while(!isPrime(i));
}
}
return sum;
}
static int findSumOfDigit(int n)
7
{
int s=0;
while(n>0)
{
s=s+n%10;
n=n/10;
}
return s;
}
static boolean isPrime(int k)
{
boolean b=true;
int d=2;
while(d<Math.sqrt(k))
{
if(k%d==0)
{
b=false;
}
d++;
}
return b;
}
public static void main ()
8
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int n=sc.nextInt();
sum of digits of the given number
int a = findSumOfDigit(n);
int b = findSumPrimeFactors(n);
System.out.println("Sum of Digits of the given number is = "+a);
System.out.println("Sum of digits of its prime factors is = "+b);
if(a==b)
System.out.print("The given number is a smith number.");
else
System.out.print("The given number is not a smith number.");
}
}

SAMPLE INPUT 1:
Entered number: 142
SAMPLE OUTPUT 1:
Sum of Digits of the given number is = 7
Sum of digits of its prime factors is = 10
The given number is not a smith number.
9
SAMPLE INPUT 2:
Entered number: 121
SAMPLE OUTPUT 2:
Sum of Digits of the given number is = 4
Sum of digits of its prime factors is = 4
The given number is a smith number..

3 WRITE PROGRAM TO INPUT ANY EVEN INTEGER


AND CHECK WHETHER IT IS A GOLDBACH
NUMBER OR NOT.

import java.util.*;
class Goldbach
{

10
void main()
{
Scanner in= new Scanner(System.in);
int i,j,n,p,b=0,c=0,s=0;
System.out.println("Enter Number");
n=in.nextInt();
p=n;
int ar[]=new int[n];
int br[]=new int[n];
if(n%2!=0
{
System.out.println("Invalid Input, Number is Odd "+n);
}
else
{
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
{
c++;
}
}
11
if((c==2)&&(i%2!=0))
{
ar[b]=i;
br[b]=i;
b++;
}
c=0;
}
System.out.println("Prime Pairs are :- ");
for(i=0;i<b;i++)
{
for(j=i;j<b;j++)
{
s=ar[i]+br[j];
if(s==p)
{
System.out.print(ar[i]+","+br[j
System.out.println();
}
}
}
System.out.println("It is GoldBach Number "+p);
}
}
12
}

SAMPLE INPUT 1:
Entered Number: 34
SAMPLE OUTPUT 1:
Prime Pairs are :-
3,31
5,29
11,23
17,17
13
It is GoldBach Number 34

SAMPLE INPUT 2:
Entered Number: 35
SAMPLE OUTPUT 2:
Invalid Input, Number is Odd 35

14
4 WRITE A PROGRAM TO CHECK WHETHER THE
ENTERED NUMBER IS CIRCULAR PRIME OR NOT.

import java.util.*;
class circular
{ boolean IsPrime(int num)
{ int k=0;
for(int i=2;i<num;i++)
{
if(num%i==0)
{
k=1; break;
}
}
if(k==1)
return false;
else
return true;
}
void main()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter the number to be checked");
int num=sc.nextInt();

15
boolean f=true;
int c=String.valueOf(num).length();
for(int i=1;i<=c;i++)
{
int r=num%10;
num= num/10;
num=(r*(int)Math.pow(10,c-1)+num);
if(IsPrime(num)==false)
{
f=false;
break;
}
}
if(f==true)
{
System.out.println("The Number is Circular Prime");
}
else
{
System.out.println("The Number is not Circular Prime");
}
}
}

16
SAMPLE INPUT 1:
Number entered by user= 131
SAMPLE OUTPUT 1:
Enter the number to be checked= 131
The Number is Circular Prime

SAMPLE INPUT 2:
Number entered by user= 249
SAMPLE OUTPUT 2:
Enter the number to be checked= 249
The Number is not Circular Prime

17
5 WRITE A PROGRAM TO INPUT A NUMBER AND
CHECK WHETHER IT IS A TECH NUMBER OR NOT.

import java.util.Scanner;
public class TechNumber
{
public static void main(String[] args)
{
int n, num, leftNumber, rightNumber, digits =
0,sum=0,sumSquare
=0;
Scanner sc = new Scanner(System.in);
System.out.print("Enter number=");
n = sc.nextInt();
num = n;
while (num > 0)
{
digits++;
num = num / 10;
}
if (digits % 2 == 0)
{
num = n;

18
rightNumber = num % (int) Math.pow(10, digits / 2);
leftNumber = num / (int) Math.pow(10, digits / 2);
sum=leftNumber+rightNumber;
sumSquare = (leftNumber + rightNumber) * (leftNumber +
rightNumber);
System.out.println("Left Numbers ="+leftNumber);
System.out.println("Right Numbers ="+rightNumber);
System.out.println("Sum of left and right numbers ="+sum);
System.out.println("Square of sum of left and right numbers
="+sumSquare);
if (n == sumSquare)
{
System.out.println("Tech Number");
}
else
{
System.out.println("Not Tech Number");
}
}
else
{ System.out.println("Not Tech Number");
}
}
}

19
SAMPLE INPUT 1:
Entered number=2025
SAMPLE OUTPUT 1:
Left Numbers =20
Right Numbers =25
Sum of left and right numbers =45
Square of sum of left and right numbers =2025
Tech Number

SAMPLE INPUT 2:
Entered Number=4862
SAMPLE OUTPUT 2:
Left Numbers =48
Right Numbers =62
Sum of left and right numbers =110
Square of sum of left and right numbers =12100
Not Tech Number

20
6 WRITE A PROGRAM TO INPUT AN ARRAY OF SIZE
N BY M AND DISPLAY THE MIRROR IMAGE OF THE
ARRAY.

import java.util.*;
class Mirror
{
void main()
{ Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number of rows :");
int r=sc.nextInt();
System.out.println("Enter the Number of Columns :");
int c=sc.nextInt();
int arr[][]=new int[r][c]; int arr1[][]=new int[r][c];
System.out.println("Enter the Elements :");
for(int i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{
arr[i][j]=sc.nextInt();
}
}
System.out.println("Original Array ");
for(int i=0;i<r;i++)
{ for(int j=0;j<c;j++)
21
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
System.out.println("Mirror Image :");
for(int i=0;i<r;i++)
{
int z=c-1;
for(int j=0;j<c;j++)
{
arr1[i][j]=arr[i][z--];
}
}
for(int i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{
System.out.print(arr1[i][j]+" ");
}
System.out.println();
}
}
}
SAMPLE INPUT 1:
22
Elements entered : 1,2,3,4,5,6,7,8,9
SAMPLE OUTPUT 1:
Enter the Number of rows : 3
Enter the Number of Columns : 3
Enter the Elements : 1,2,3,4,5,6,7,8,9
Original Array Mirror Image :
1 2 3 3 2 1
4 5 6 6 5 4
7 8 9 9 8 7

SAMPLE INPUT 2:
Elements entered: 1,2,3,4,5,6
SAMPLE OUTPUT 2:
Enter the Number of rows : 2
Enter the Number of Columns : 2
Enter the Elements : 1,2,3,4,5,6
Original Array Mirror Image :
1 2 3 3 2 1
4 5 6 6 5 4

23
7 WRITE A PROGRAM TO INPUT AN ARRAY AND
PRINT THE SUM OF PRIME NUMBERS IN THE
ARRAY

import java.util.*;
class prime
{
boolean prime(int p)
{
int flg=0;
for(int i=2;i<p;i++)
{
if(p%i==0)
flg=1;
}
if(flg==1)
return false;
else
return true;
}

void mains()
{

24
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of rows in the array:");
int r=sc.nextInt();
System.out.println("enter the number of columns in the array :");
int c=sc.nextInt();
int arr[][]=new int[r][c];
System.out.println("Enter the element in the array :");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
arr[i][j]=sc.nextInt();
}
}
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
System.out.print("Sum of the prime number :");
int sum=0;
25
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if((prime(arr[i][j])==true)&&(arr[i][j]!=1)&&(arr[i][j]!=1))
{
System.out.print(arr[i][j]+" + " );
sum=sum+arr[i][j];
}
}
}
System.out.print("="+sum);
}
}

26
SAMPLE INPUT 1:
Entered Elements: 1,2,3,4,5,6
SAMPLE OUTPUT 1:
Enter the number of rows in the array: 2
Enter the number of columns in the array : 3
Enter the element in the array : 1,2,3,4,5,6
1 2 3
4 5 6
Sum of the prime number :2 + 3 + 5 + =10

SAMPLE INPUT 2:
Entered Elements: 1,2,3,4,5,6,7,8,9
SAMPLE OUTPUT 2:
Enter the number of rows in the array: 3
Enter the number of columns in the array : 3
Enter the element in the array : 1,2,3,4,5,6,7,8,9
1 2 3
4 5 6 0
7 8 9
Sum of the prime number :2 + 3 + 5 + 7 + =17

27
8 WRITE A PROGRAM TO INPUT AN ARRAY AND FIND
THE SADDLE POINT.

import java.util.*;
class Saddle
{
void mains()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter rows :");
int r=sc.nextInt();
System.out.println("Enter columns :");
int c=sc.nextInt();
int arr[][]=new int[r][c];int no=0;
System.out.println("Enter Elements :");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
arr[i][j]=sc.nextInt();
}
}

28
System.out.println("Double Dimensional Array :");
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}

for(int i=0;i<r;i++)
{
int p=0;int m=0;int sum=0;
sum=arr[i][0];
for(int j=0;j<c;j++)
{
if(sum>arr[i][j])
sum=arr[i][j];
p=j;
m=arr[i][0];
for(int k=0;k<c;k++)
{
if(m<arr[k][p])
m=arr[k][p];
29
}
if(sum==m)
System.out.println("Saddle Point : " +sum);
}
}
}
}

SAMPLE INPUT 1:
30
Entered Elements: 1,2,3,4
SAMPLE OUTPUT 1:
Enter rows : 2 Enter columns : 2
Enter Elements :1,2,3,4
Double Dimensional Array :
1 2
3 4
Saddle Point : 3

SAMPLE INPUT 2:
Entered Elements: 1,2,3,4
SAMPLE OUTPUT 2:
Enter rows : 2 Enter columns : 2
Enter Elements :1,2,3,4
Double Dimensional Array :
1 2
3 4
Saddle Point : 3

31
9 WRITE A PROGRAM TO ENTER A SIZE OF AN
ARRAY, FILL THE ARRAY AND THE ROTATE THE
ARRAY LEFT COLUMN-WISE.

import java.util.*;
class rotation
{
static void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter row: ");
int r=sc.nextInt(); int x,j;
System.out.print("Enter column: ");
int c=sc.nextInt(); int ar[][]=new int[r][c];
System.out.println("Fill the array");
for(int i=0;i<r;i++)
{ for(j=0;j<c;j++)
{
ar[i][j]=sc.nextInt();
}
}
for(int i=0;i<r;i++)
{ for(j=0;j<c;j++)
{
32
System.out.print(ar[i][j]+" ");
}
System.out.println();
}
System.out.println("Original Array:");
for(int i=0;i<r;i++)
{
x=ar[i][0];
for(j=0;j<c-1;j++)
{
ar[i][j]=ar[i][j+1];
}
ar[i][j]=x;
}
System.out.println("New Array:");
for(int i=0;i<r;i++)
{ for(j=0;j<c;j++)
{ System.out.print(ar[i][j]+" ");
}
System.out.println();
}
}
}
SAMPLE INPUT 1:
33
Entered Array:
1 2
3 4
SAMPLE OUTPUT1:
Enter row: 2 Enter column: 2
Fill the array:
1,2,3,4
Original Array New Array
1 2 2 1
3 4 4 3

SAMPLE INPUT 2:
Entered Array:
1 2
3 4
SAMPLE OUTPUT2:
Enter row: 2 Enter column: 2
Fill the array:
2,4,6,3
Original Array New Array
2 4 4 2
6 3 3 6

34
10 WRITE A PROGRAM TO ENTER AN ODD NUMBER
AND PRINT THE MAGIC SQUARE OF THAT SIZE.

import java.util.*;
class magic_s
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter an odd number:");
int n=sc.nextInt();
int c=n/2;int r=n-1;
int ar[][]=new int[n][n];
ar[r][c]=1;
for(int i=2;i<=n*n;i++)
{
if(ar[(r+1)%n][(c+1)%n]==0)
{
r=(r+1)%n;
c=(c+1)%n;
}
else
{
r=(r-1+n)%n;
}
35
ar[r][c]=i;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(ar[i][j]<10)
System.out.print("0"+ar[i][j]+" ");
else
System.out.print(ar[i][j]+" ");
}
System.out.println();
}
}
}

SAMPLE INPUT 1:
Enter an odd number: 3

36
SAMPLE OUTPUT 1:
4 9 2
3 5 7
8 1 6

SAMPLE INPUT 2:
Enter an odd number: 5
SAMPLE OUTPUT 2:
11 18 25 02 09
10 12 19 21 03
04 06 13 20 22
23 05 07 14 16
17 24 01 08 15

37
11 WRITE A MENU DRIVEN PROGRAM TO INPUT A
STRING AND APPEND, REMOVE OR INSERT ANY
STRING AT ENTERED POSITION TO THE ENTERED
STRING.

import java.util.*;
class menu
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the String :");
String a=sc.nextLine();
System.out.println(" Menu Driven ");
System.out.println("1. Append a string ");
System.out.println("2. Remove a String ");
System.out.println("3. Insert a String ");
System.out.println("4. To exit the program ");
System.out.print("Enter your choice: ");
int n=sc.nextInt();
StringBuffer sb=new StringBuffer(a);
switch(n)
{

38
case 1:
System.out.print("Enter the String to append :");
String s=sc.next();
String s1=" " + s ;
sb=sb.append(s1);
System.out.println("New String : " + sb);
break;

case 2:
System.out.println("Enter the string to delete :");
String i=sc.next();
int p=a.indexOf(i);
int q=p+i.length()+1;
sb=sb.delete(p,q);
System.out.println("New String : "+sb);
break;

case 3:
StringTokenizer st=new StringTokenizer(a);
int nim=st.countTokens();
String arr[]=new String[nim];
for(int l=0;l<nim;l++)
{
arr[l]=st.nextToken();
39
}
System.out.println("Enter the position :");
int pos=sc.nextInt();
int pos_a=pos-1;
String op=arr[pos];
int ins=a.indexOf(op);
System.out.println("Enter the String:");
String y=sc.next();
String iy=y+" ";
sb=sb.insert(ins,iy);
System.out.println("New String : " +sb);
break;

case 4:
System.exit(0);
}
}
}

40
SAMPLE INPUT 1:
String Entered= I will try hard to achieve above 95 percent in board
SAMPLE OUTPUT 1:
Enter the String :
I will try hard to achieve above 95 percent in board
1. Append a string
2. Remove a String
3. Insert a String
4. To exit the program
Enter your choice : 1
Enter the String to append : exams.
New String : I will try hard to achieve above 95 percent in board
exams.

SAMPLE INPUT 2:
Entered String= I will try to achieve above 95 percent in board exams.
SAMPLE OUTPUT 2:
Enter the String :
I will try hard to achieve above 95 percent in board exams.
Menu Driven
1. Append a string
2. Remove a String
3. Insert a String
4. To exit the program
41
Enter your choice: 2
Enter the string to delete : above
New String : I will try hard to achieve 95 percent in board exams.

42
12 WRITE A PROGRAM TO ARRANGE THE WORDS
OF A SENTENCE ENTERED BY USER
ALPHABETICALLY IN ASCENDING ORDER.

import java.util.*;
class alphabetical_ascending
{
void main()
{
Scanner sc=new Scanner(System.in); System.out.println("ENTER
ANY SENTENCE :");
String a=sc.nextLine();
String t=a.toUpperCase();
StringTokenizer st=new StringTokenizer(t);
int n=st.countTokens();
String ar[]=new String[n];
for(int i=0;i<n;i++)
{
ar[i]=st.nextToken();
}
for(int i=0;i<n;i++)
{
for(int j=(i+1);j<n;j++)

43
{
if(ar[i].compareTo(ar[j])>0)
{
String z=ar[i];
ar[i]=ar[j];
ar[j]=z;
}
}
}
for(int i=0;i<n;i++)
{
System.out.print(ar[i]+" ");
}
}
}

44
SAMPLE INPUT 1:
Entered Sentence: I love india
SAMPLE OUTPUT 1:
Arranged sentence= I INDIA LOVE

SAMPLE INPUT 2:
Entered Sentence: I hate this kind of behaviour
SAMPLE OUTPUT 2:
Arranged sentence= BEHAVIOUR HATE I KIND OF THIS

45
13 WRITE A PROGRAM TO INPUT A SENTENCE.
CONVERT FIRST AND LAST LETTER OF EACH
WORD TO UPPER CASE AND DISPLAY THEM
ALPHABETICALLY.

import java.util.*;
class alpha_initial
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("ENTER ANY SENTENCE :");
String a=sc.nextLine();
String n=a.toUpperCase();
StringTokenizer st=new StringTokenizer(n); int
o=st.countTokens();
String m;char c;char b;String wrd="";
String arr[]=new String[o];
for(int i=0;i<o;i++)
{
arr[i]=st.nextToken();
}
for(int i=0;i<o;i++)

46
{
String u=arr[i];
c=u.charAt(0);
int s=u.length()-1;
b=u.charAt(s);
wrd=wrd+c+b;
}
System.out.println(wrd); String str="";
for(char ch='A';ch<'Z';ch++)
{
for(int i=0;i<wrd.length();i++)
{
if(wrd.charAt(i)==ch)

{
str=str+wrd.charAt(i);
}
}
}
System.out.println(“Arranged letters in alphabetical order=”+str);
}
}

47
SAMPLE INPUT 1:
Entered Sentence= The seven deadly sins
SAMPLE OUTPUT 1:
TESNDYSS
Arranged letters in alphabetical order=DENSSSTY

SAMPLE INPUT 2:
Entered Sentence= That time when I got reincarnated as a slime
SAMPLE OUTPUT 2:
TTTEWNIIGTRDASAASE
Arranged letters in alphabetical order=AAADEEGIINRSSTTTTW

48
14 WRITE A PROGRAM TO ENTER A STRING AND
CHECK IF IT IS PALINDROME OR NOT.

import java.util.*;
class palin_string
{
boolean isPalindrome(String x)
{
String rev = "";
boolean ans = false;
for (int i = x.length() - 1; i >= 0; i--) {
rev = rev + x.charAt(i);
}
if (x.equals(rev))
{
ans = true;
}
return ans;
}

void main()
{
Scanner sc=new Scanner(System.in);

49
System.out.println("Enter the string to be checked");
String x = sc.next();
x= x.toLowerCase();
boolean A = isPalindrome(x);
System.out.println(A);
if(A==true)
System.out.println("Entered string is Palindrome");
else
System.out.println("Entered string is not Palindrome");
}
}

50
SAMPLE INPUT 1:
Entered String= mom
SAMPLE OUTPUT 1:
true
Entered string is Palindrome

SAMPLE INPUT 2:
Entered String= mad
SAMPLE OUTPUT 2:
false
Entered string is not Palindrome

51
15 WRITE A PROGRAM TO PRINT THE SUBSET OF
THREE CHARACTERS

import java.util.*;
class subset
{
void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter first character");
char x=sc.next().charAt(0);
System.out.println("Enter second character");
char y=sc.next().charAt(0);
System.out.println("Enter third character");
char z=sc.next().charAt(0);
String str=""+x+y+z;
int len=str.length();
int temp=0;
String ar[]=new String[len*(len+1)/2];
for(int i=0;i<len;i++)
{
for(int j=i;j<len;j++)
{
ar[temp]=str.substring(i,j+1);

52
temp++;
}
}
System.out.println("All subsets of given string are:");
for(int i=0;i<ar.length;i++)
{
System.out.println(ar[i]);
}
}
}

53
SAMPLE INPUT 1:
Entered String= AYU
SAMPLE OUTPUT 1:
All subsets of given string are:
A
AY
AYU
Y
YU
U
SAMPLE INPUT 2:
Entered String= DIX
SAMPLE OUTPUT 2:
D
DI
DIX
I
IX
X

54

You might also like