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

Program Print

java programing class 11th icse project programs

Uploaded by

Rakshit Soni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Program Print

java programing class 11th icse project programs

Uploaded by

Rakshit Soni
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

PROGRAM 1 :- LetterSeq

import java.util.Scanner;

class LetterSeq

public static void main(String args[])

Scanner in = new Scanner(System.in);

System.out.print("Enter string: ");

String s = in.nextLine();

String str = s.toUpperCase();

int count = 0;

int len = str.length();

for (int i = 0; i < len - 1; i++) {

if (str.charAt(i) == str.charAt(i + 1))

count++;

System.out.println("Double Letter Sequence Count = " + count);

}
PROGRAM 2 :- Q3

import java.util.Scanner;

class Q3

public static void main(String args[])

int a[]=new int[10], i,ln=0,lnp=0,sn=0,snp=0;

Scanner sc=new Scanner(System.in);

System.out.println("Enter 10 numbers");

for(i=0; i<10; i++)

a[i]=sc.nextInt();

for(i=0; i<10; i++)

if(i==0)

ln=a[i];

sn=a[i];

lnp=i;

snp=i;

else if(a[i]>ln)

ln=a[i];

lnp=i;

else if(a[i]<sn)
{

sn=a[i];

snp=i;

a[lnp]=sn;

a[snp]=ln;

System.out.println("\nArray after interchanging largest with the smallest");

for(i=0; i<10; i++)

System.out.print(a[i]+" ");

}
PROGRAM 3 :- Q8

import java.util.Scanner;

public class Q8

public static void main(String args[])

int a[]=new int[10], i,t;

Scanner sc=new Scanner(System.in);

System.out.println("Enter 10 numbers");

for(i=0; i<10; i++)

a[i]=sc.nextInt();

for(i=0; i<10; i=i+2)

t=a[i];

a[i]=a[i+1];

a[i+1]=t;

System.out.println("\nModified array after interchanging the consecutive numbers");

for(i=0; i<10; i++)

System.out.print(a[i]+" ");

}
PROGRAM 4 :- StdCodes

import java.util.Scanner;

public class StdCodes

public static void main(String args[]) {

final int SIZE = 10;

Scanner in = new Scanner(System.in);

String cities[] = new String[SIZE];

String stdCodes[] = new String[SIZE];

System.out.println("Enter " + SIZE +

" cities and their STD codes:");

for (int i = 0; i < SIZE; i++) {

System.out.print("Enter City Name: ");

cities[i] = in.nextLine();

System.out.print("Enter its STD Code: ");

stdCodes[i] = in.nextLine();

System.out.print("Enter name of city to search: ");

String city = in.nextLine();

int idx;

for (idx = 0; idx < SIZE; idx++) {

if (city.compareToIgnoreCase(cities[idx]) == 0) {

break;

if (idx < SIZE) {


System.out.println("Search Successful");

System.out.println("City: " + cities[idx]);

System.out.println("STD Code: " + stdCodes[idx]);

else {

System.out.println("Search Unsuccessful");

}
PROGRAM 5 :- P6

import java.util.Scanner;

class P6

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

int P[] = new int[6];

int Q[] = new int[4];

int R[] = new int[10];

int i = 0;

System.out.println("Enter 6 elements of array P:");

for (i = 0; i < P.length; i++) {

P[i] = in.nextInt();

System.out.println("Enter 4 elements of array Q:");

for (i = 0; i < Q.length; i++) {

Q[i] = in.nextInt();

i = 0;

while(i < P.length) {

R[i] = P[i];

i++;

int j = 0;
while(j < Q.length) {

R[i++] = Q[j++];

System.out.println("Elements of Array R:");

for (i = 0; i < R.length; i++) {

System.out.print(R[i] + " ");

}
PROGRAM 6 :- P7

import java.util.*;

class P7

public static void main(String args[])

Scanner sc = new Scanner(System.in);

int a[][] = new int[5][5];

int i,j,max=0,min=0;

System.out.println("enter 25 numbers:");

for(i=0;i<5;i++)

for(j=0;j<5;j++)

a[i][j]=sc.nextInt();

for(i=0;i<5;i++)

for(j=0;j<5;j++)

if(i==0 && j==0)

max=min=a[i][j];

if(a[i][j]>max)

max=a[i][j];

if(a[i][j]<min)

min=a[i][j];

}
System.out.println("Largest number: "+max);

System.out.println("Smallest number: "+min);

}
PROGRAM 7 :- diagonaldisplay

import java.util.*;

class diagonaldisplay

public static void main(String args[])

Scanner sc = new Scanner(System.in);

int n[][] = new int[5][5];

int i,j,s;

System.out.println("Enter numbers in array:");

for(i=0;i<5;i++)

for(j=0;j<5;j++)

n[i][j]=sc.nextInt();

System.out.println("Elements of array:");

for(i=0;i<5;i++)

for(j=0;j<5;j++)

System.out.print(n[i][j]+"\t");

System.out.println();

int ld1 = n[0][0], sd1 = n[0][0];

int ld2 = n[0][0], sd2 = n[0][4];

for(i=0;i<5;i++)

for(j=0;j<5;j++)
{

if(i==j)

if(n[i][j]>ld1)

ld1=n[i][j];

if(n[i][j]<sd1)

sd1=n[i][j];

if(i+j==4)

if(n[i][j]>ld2)

ld2=n[i][j];

if(n[i][j]<sd2)

sd2=n[i][j];

System.out.println("Largest number of diagonal 1 : "+ld1);

System.out.println("Smallest number of diagonal 1 : "+sd1);

System.out.println("Largest number of diagonal 2 : "+ld2);

System.out.println("Smallest number of diagonal 2 : "+sd2);

}
PROGRAM 8 :- SelectionSort

import java.util.Scanner;

class SelectionSort

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

double weightArr[] = new double[10];

System.out.println("Enter weights of 10 people: ");

for (int i = 0; i < 10; i++) {

weightArr[i] = in.nextDouble();

for (int i = 0; i < 9; i++) {

int idx = i;

for (int j = i + 1; j < 10; j++) {

if (weightArr[j] > weightArr[idx])

idx = j;

double t = weightArr[i];

weightArr[i] = weightArr[idx];

weightArr[idx] = t;

System.out.println("Sorted Weights Array:");

for (int i = 0; i < 10; i++) {

System.out.print(weightArr[i] + " ");

}
PROGRAM 9 :- BubbleSortDsc
import java.util.Scanner;

class BubbleSortDsc

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

int n = 10;

int arr[] = new int[n];

System.out.println("Enter the elements of the array:");

for (int i = 0; i < n; i++) {

arr[i] = in.nextInt();

//Bubble Sort

for (int i = 0; i < n - 1; i++) {

for (int j = 0; j < n - i - 1; j++) {

if (arr[j] < arr[j + 1]) {

int t = arr[j];

arr[j] = arr[j+1];

arr[j+1] = t;

System.out.println("Sorted Array:");

for (int i = 0; i < n; i++) {

System.out.print(arr[i] + " ");

}
PROGRAM 10 :- Rearrange

import java.io.*;

import java.util.*;

class Rearrange

private String wrd;

private String newwrd;

public Rearrange()

wrd =new String();

newwrd = new String();

public void readword() throws IOException

Scanner sc=new Scanner(System.in);

System.out.print("Enter the words: ");

wrd=sc.next();

public void freq_vow_con()

wrd=wrd.toUpperCase();

int v=0;

int c=0;

for(int i=0;i<wrd.length();i++)

char ch=wrd.charAt(i);

if ( Character.isLetter(ch))

switch (ch)

case 'A':
case 'E':

case 'I':

case 'O':

case 'U':

v++;

break;

default:

c++;

System.out.println("Frequency of vowels: "+v);

System.out.println("Frequency of consonants: "+c);

public void arrange()

String v=new String();

String c=new String();

wrd = wrd.toUpperCase();

for(int i=0;i<wrd.length();i++)

char ch=wrd.charAt(i);

if ( Character.isLetter(ch))

switch (ch)

case 'A':

case 'E':

case 'I':

case 'O':

case 'U':
v+=ch;

break;

default:

c+=ch;

newwrd=v+c;

public void display()

System.out.println("Original word: "+wrd);

System.out.println("Rearranged word: "+newwrd);

public static void main(String []args) throws IOException

Rearrange obj=new Rearrange();

obj.readword();

obj.freq_vow_con();

obj.arrange();

obj.display();

}
PROGRAM 11 :- ArmNum

import java.io.*;

import java.util.*;

class ArmNum

static int n;

static int l;

public ArmNum(int num)

n=num;

l=0;

for(int i=n;i!=0;i/=10)

l++;

public int sumPow(int i)

if(i<10)

return (int)Math.pow(i,1);

return (int)Math.pow(i%10,1)+ sumPow(i/10);

public void isArmstrong()

if(n==sumPow(n))

System.out.println(n+"is an Armstrong Number");

else

System.out.println(n+"is not an Armstrong Number");

public static void main(String []args)throws IOException

Scanner sc=new Scanner(System.in);

System.out.print("N=");
int num=sc.nextInt();

ArmNum obj=new ArmNum(num);

obj.isArmstrong();

}
PROGRAM 12 :- Perfect

import java.io.*;

import java.util.*;

class Perfect

private int num;

private int f;

public Perfect(int num)

this.num=num;

f=1;

public int sumOfFactors(int i)

if(i==f)

return 0;

else if(i%f==0)

return f++ + sumOfFactors(i);

else

f++;

return sumOfFactors(i);

public void check()

if (num==sumOfFactors(num))
{

System.out.println(num+"is a perfect number");

else

System.out.println(num+"Not a perfect number");

public static void main (String []args) throws IOException

Scanner sc=new Scanner (System.in);

System.out.println("Enter the number:");

int n=sc.nextInt();

Perfect obj= new Perfect(n);

obj.check();

}
PROGRAM 13 :- Palin

import java.io.*;

import java.util.*;

class Palin

int num;

int revnum;

Palin()

num=0;

revnum=0;

void accept() throws IOException

Scanner sc=new Scanner (System.in);

System.out.println("Enter the number:");

String a=sc.next();

num=Integer.parseInt(a);

int reverse(int y)

int len=(y+"").length();

if(len==1)

return y;

else

return (((y%10)*(int)Math.pow(10,len-1))+reverse(y/10));

}
void check()

revnum=reverse(num);

if(num==revnum)

System.out.println("/n Number is palindrome");

else

System.out.println("/n Number is not palindrome");

public static void main (String args[]) throws IOException

Palin p=new Palin();

p.accept();

p.check();

}
PROGRAM 14 :- SwapSort
import java.io.*;

import java.util.*;

class SwapSort

String wrd;

int len;

String swapwrd;

String sortwrd;

SwapSort()

wrd="";

len=0;

swapwrd="";

sortwrd="";

void readword() throws IOException

Scanner sc=new Scanner (System.in);

System.out.println("Enter word: ");

wrd=sc.next();

void swapwrd()

String w=wrd;

swapwrd=w.charAt(w.length()-1)+w.substring(1,w.length()-1)+w.charAt(0);

void sortwrd()

String w=wrd;

char[] charArray=w.toCharArray();

int length=charArray.length;

for(int i=0;i<length;i++)
{

for (int j=0;j<length;j++)

if(charArray[j]<charArray[i])

char temp=charArray[i];

charArray[i]=charArray[j];

charArray[j]=temp;

for(char c:charArray)

sortwrd=sortwrd+c;

void display()

System.out.println("Original word: "+wrd);

System.out.println("Swapped word: "+swapwrd);

System.out.println("Sorted Array: "+sortwrd);

public static void main(String []args) throws IOException

SwapSort obj=new SwapSort();

obj.readword();

obj.swapwrd();

obj.sortwrd();

obj.display();

}
PROGRAM 15 :- Disarium

import java.io.*;

import java.util.*;

class Disarium

public static void main (String []args)

Scanner sc=new Scanner(System.in);

System.out.println("Enter a number: ");

int n=sc.nextInt();

int copy=n,d=0,sum=0;

String s=Integer.toString(n);

int len=s.length();

while(copy>0)

d=copy%10;

sum=sum+(int)Math.pow(d,len);

len--;

copy=copy/10;

if (sum==n)

System.out.println("Is a disarium number");

else

System.out.println("Is not a disarium number");

You might also like