Professional Documents
Culture Documents
Board Programes
Board Programes
Algorithm
1. Initialize the two strings st1, st2 using string tokenizer.
2. Condition checked whether the two tokens finished, hasMoreTokens().
3. Whenever a word is reached each time count c, c2 is increased of two strings.
import java.util.*;
class tokens
{
public static void main(String str,String str1)
{
int c=0,c1=0;
String str2,str3;
StringTokenizer st1= new StringTokenizer(str);
StringTokenizer st2= new StringTokenizer(str1);
System.out.println("The different tokens");
while(st1.hasMoreTokens())
{
str2=st1.nextToken();
System.out.println(str2);
c=c+1;
}
while(st2.hasMoreTokens())
{
str3=st2.nextToken();
System.out.println(str3);
c1=c1+1;
}
System.out.println("Number of tokens in first program="+c);
System.out.println("Number of tokens in second string="+c1);
}
}
// pgm to display the sorted array of 10 elements using the bubble sort
Algorithm
Run a nested for loop to traverse the input array using two variables i and j, such that 0 ≤ i < n-1
and 0 ≤ j < n-i-1
2.If arr[j] is greater than arr[j+1] then swap these adjacent elements, else move on
3.Print the sorted array
import java.util.*;
public class bubble
{
public static void main(String[] args)
{
int n=10, i, j, x=0;
int array[] = new int[10];
Scanner s = new Scanner(System.in);
import java.util.*;
class SmithNumber
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int n,f=2,m,t,s1=0,s2=0,d;
System.out.println("Enter the number");
n=sc.nextInt();
m=n;
while(n>1)
{
if(n%f==0)
{
t=f;
while(t!=0)
{
d=t%10;
s1+=d;
t/=10;
}
n=n/f;
}
else
f++;
}
t=m;
while(t!=0)
{
d=t%10;
s2+=d;
t/=10;
}
if(s1==s2)
System.out.println("Smith number");
else
System.out.println("Not a smith number");
}
}