Monday, December 23, 2024

BlueJ Program Eliminating Duplicate Letters From A Senrence

 import java.util.*;
class S
{   
 String str,str1;
    int i,j,len,c;
    char ch[],ch1;
    Scanner sc=new Scanner(System.in);
    public void show() 
    {
       str1="";
       c=0;
       System.out.print("\nEnter the sentence:");
      str=sc.nextLine().toLowerCase();
      len=str.length();
      ch=new char[len];
      System.out.print("\nEntered sentence:"+str);
      for(i=0;i<len;i++)
      {
         ch1=str.charAt(i);
         for(j=0;j<c;j++)
         {
           if( str1.charAt(j)==ch1)           
           break;
         }
         if(j==c)
         {
         str1=str1+ch1;
         ch[c++]=ch1;
        }
    }
     
     System.out.print("\nSentence elimination of repeated letters:"+str1);     
    
       } 
    }
         

Monday, December 16, 2024

BlueJ Program To Display Words of A Sentence In Alphabetical Order

 import java.util.*;
class Sen
{   
 String arr[]=new String[15];
    String str,t;
    int i,j,c;
    Scanner sc=new Scanner(System.in);
    public void show() 
    {
       System.out.print("\nEnter the sentence:");
      str=sc.nextLine()+" ";
      c=0;
      while(true)
      {
          i=str.indexOf(' ');
          if(i<0)
          break;
          arr[c++]=str.substring(0,i);
          str=str.substring(i+1);
      }
       
     for(i=0;i<c-1;i++)
     {
         for(j=i+1;j<c;j++)
     {
              if(arr[i].compareToIgnoreCase(arr[j])>0)
              {
                  t=arr[i];
                  arr[i]=arr[j];
                  arr[j]=t;
              }
     }
    }
     
     System.out.print("\nWords in alphabetical order\n");
     for(i=0;i<c;i++)
     {
         
        System.out.print(" "+arr[i]);
    }
    
       } 
    }
         

BlueJ Program Upper Triangular Matrix Checking

What is upper triangular matrix?

A matrix where all elements below the left diagonal are zero is called upper triangular matrix.

 import java.util.*;
class UTMatrix
{   
    int arr[][];
    int i,j,c,n;
    Scanner sc=new Scanner(System.in);
    public void show() 
    {
       System.out.print("\nEnter the size of array:");
       n=sc.nextInt();
       arr=new int[n][n];
     for(i=0;i<n;i++)
     {
         for(j=0;j<n;j++)
     {
              System.out.print("\nValue:");
              arr[i][j]=sc.nextInt();
     }
    }
     
     System.out.print("\nMatrix Values\n");
     for(i=0;i<n;i++)
     {
         for(j=0;j<n;j++)
     {
        System.out.print(" "+arr[i][j]);
    }
    System.out.println();
}
          for(i=0;i<n;i++)
     {
         for(j=0;j<n;j++)
     {
         if(arr[i][j]!=0 && j<i)
        {
         c=1;
         break;
        }
    } 
    } 
        if(c==0)
        System.out.print("\nThis is an upper traingular Matrix");
        else
        System.out.print("\nThis is not an upper traingular Matrix");
       } 
    }
         

Tuesday, December 10, 2024

BlueJ Program To Check For 2-D Array With Binary Values

What is array with binary values? If an array contains only 0 and 1, it is called binary array.

 import java.util.*;
class Arr
{   
    int arr[][]=new int [3][4];
    int i,j,c;
    Scanner sc=new Scanner(System.in);
    public void show() 
    {
        c=0;
     for(i=0;i<3;i++)
     {
         for(j=0;j<4;j++)
     {
              System.out.print("\nValue:");
              arr[i][j]=sc.nextInt();
     }
    }
     
     System.out.print("\nValues=");
     for(i=0;i<3;i++)
     {
         for(j=0;j<4;j++)
     {
        System.out.print(" "+arr[i][j]);
    }
    System.out.println();
}
          for(i=0;i<3;i++)
     {
         for(j=0;j<4;j++)
     {
         if(arr[i][j]!=0 || arr[i][j]!=1)
        {
         c=1;
         break;
        }
    } 
    } 
        if(c==0)
        System.out.print("\nArray with binary values");
        else
        System.out.print("\nArray with not binary values");
       } 
    }
         

Thursday, December 5, 2024

BlueJ Program Display The Number With Number of Factors Among Few Elements In An Array

 import java.util.*;
class Arr
{   
    int arr[];
    int i,j,n,m,no,c,max;
    Scanner sc=new Scanner(System.in);
    public void show() 
    {
        System.out.print("\nHow many elements:");
              n=sc.nextInt();  
              arr=new int[n];
     for(i=0;i<n;i++)
     {
              System.out.print("\nValue:");
              arr[i]=sc.nextInt();
     }
     max=0;
     System.out.print("\nValues=");
     for(i=0;i<n;i++)
     System.out.print(" "+arr[i]);
          for(i=0;i<n;i++)
     {
         no=arr[i];
         c=0;
         for(j=1;j<=no;j++)
         {
             if(no%j==0)
             c++;
            } 
            if(c>max)
            {
            max=c;
            m=no;
            }
        }
            
            System.out.print("\nNumber with maximum factors="+m + " and number of factors "+max);
         }
       }        
         

BlueJ Program Display Maximum Prime Value From An Array of 20 Elements

 import java.util.*;
class Arr
{   
    int arr[]=new int[20];
    int i,j,n,c,max;
    Scanner sc=new Scanner(System.in);
    public void show() 
    {
         
     for(i=0;i<20;i++)
     {
              System.out.print("\nValue:");
              arr[i]=sc.nextInt();
     }
     max=0;
     System.out.print("\nValues=");
     for(i=0;i<20;i++)
     System.out.print(" "+arr[i]);
          for(i=0;i<20;i++)
     {
         n=arr[i];
         c=0;
         for(j=1;j<=n;j++)
         {
             if(n%j==0)
             c++;
            } 
            if(c==2 && n>max)
            max=n;
            }                     
            if(max==0)
            System.out.print("\nList has no Prime Number");
            else
            System.out.print("\nMax Prime "+max);
         }
       }

Tuesday, November 5, 2024

BlueJ Program On 2 D Array and Sorting


Details of The Program: CLICK HERE

import java.io.*; 
public class P 
{ 
void sort(int arr[])          //Taking single dimension array as parameter 
{

int i, j, size = arr.length, temp,flag;

/*'size' holds the number of values in the array */ 
for(i=0;i 
{

flag=0; 
/*Sorting using bubble sort technique, so if there is no exchange of values in one pass there is no need to run the loop */ 
for(j=0;j 
{ 
if(arr[j]>arr[j+1])

{
flag=1; temp = arr[j]; 
arr[j] = arr[j+1]; 
arr[j+1] = temp; 
}

} 
if(flag==0)

break;
}

}

void show(int arr[][]) /*Taking 2D array as parameter*/ 
{

int i, j; for(i=0;i

{

for(j=0;j 
/* arr[i] gives one row at a time. arr[i].length gives the number of values in each row */ 
{ 
System.out.print(arr[i][j]+"\t"); 
}

System.out.println();

} 
}
 void sort2D(int arr[][]) 
{ 

/* In java, array is an object, so here the function calling technique is call be reference means any changes made to the formal parameter in this function will be reflected in the original parameter.*/


int i, j; 
for(i=0;i 
{ 
sort(arr[i]); 
} 
}
public static void main(String args[])throws Exception 
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

P obj = new P(); int arr[][], m, n, i, j; 
System.out.println("Enter the number of rows: "); 
m = 
Integer.parseInt(br.readLine()); 
System.out.println("Enter the number of columns: ");
n = Integer.parseInt(br.readLine()); 
if(m< 2 && m >9||n >9 && n< 2) 
{

System.out.println("Matrix out of range"); System.exit(0);

} 
arr = new int[m][n]; 
for(i=0;i< 
{
System.out.println("Enter values for row no "+(i+1) + ":"); for(j=0;j
{

System.out.print("\nColumn No " + (j+1) + ":"); arr[i][j] = Integer.parseInt(br.readLine()); 
} 
}
System.out.println("Original Matrix: ");
obj.show(arr); 
obj.sort2D(arr);

System.out.println("Matrix after sorting rows: "); obj.show(arr);
}
}

Variable Description

Type
Name
Use
BufferedReader
br
Intakes limit from user
int
arr
2 D array to hold the values
Int
m
Holds no of rows in the array
int
n
Holds no of columns in the


array

int
I,j
Loop Control Variable
int
size
Holds the no of elements in


each row the array
Algorithm




Step 1: Create BufferedReader object ‘br’ and int type variables ‘n’ and 'm' to store the column and row size of the 2 D array.

Step 2: Values of ‘n’ and 'm' are checked for validity and if it is invalid, terminate the program otherwise create the 2 D array 'arr'.

Step 3: Stores the values in the two dimensional array 'arr'.

Step 4: Display the original array


Step 5: Pass the two dimensional array to function 'sort2D()' which sends each rows of the 2 d array to 'sort()' function which sorts the elements bubble sort technique.


Back To 2018 Computer Practical Paper: CLICK HERE

Sunday, April 28, 2024

Program To Check Neon number Using BlueJ

What is neon number:


A neon number is that where sum of digits of square of the number is equal to the number.
For example if the input number is 9, it's square is 9*9 = 81 and sum of the digits is 9. 9 is a neon number


Java Program to check neon number


Download eBook on BlueJ 
import java.io.*;
class Neon
{
int n,sq,sum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void showNeon() throws Exception
{
 System.out.println("Enter the number:");
 n=Integer.parseInt(br.readLine());
 sq=n*n;
 while(sq>0)
{
 sum=sum+sq%10;
 sq=sq/10;
}
if(n==sum)
 System.out.println(n+ " is a neon number");
else
 System.out.println(n+ " is not a neon number");
}
public static void main(String args[])throws Exception
{
 Neon ob=new Neon();
ob.showNeon();
}
}

BlueJ Program On Neon Numbers Between 1 And 500

import java.io.*;
class Neon
{
int i,sq,sum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public void showNeon() throws Exception
{
for(i=1;i<=500;i++)
{
sum=0;
 sq=i*i;
 while(sq>=1)
{
 sum=sum+sq%10;
 sq=sq/10;
}
if(i==sum)
 System.out.println(i+ " is a neon number");
}
}
public static void main(String args[])throws Exception
{
 Neon ob=new Neon();
ob.showNeon();
}
}

Related PostBlueJ Programs on Number



Subscribe via email

Enter your email address:

Delivered by FeedBurner