Write a java program to count the frequency of words
import java.io.*;
import java.util.*;
public class FrequencyOfWords
{
public static void main(String[] args)
{
System.out.print("\nEnter Some Text:");
Scanner input=new Scanner(System.in);
String text = input.nextLine();
String ans = "";
do
{
System.out.print("\nEnter A Word You Want To Verify The Frequency:");
String word = input.nextLine();
int count = 0;
StringTokenizer st = new StringTokenizer(text);
while (st.hasMoreTokens())
{
if (st.nextToken().equals(word))
{
count++;
}
}
System.out.println("\nFrequency of \"" + word + "\" is " + count + " times");
System.out.print("\nDo You Want Verify The Frequency Of One More Word[Y/N]:");
ans = input.nextLine();
} while (ans.equals("Y") || ans.equals("y"));
}
}
Click Here to Download
Write a program to store coordinates ( x, y, z) for data points in 3 Dimensional space. Prompt for how many points to consider and then collect the coordinates as x1, y1, z1, x2, y2, z2, ........ xn, yn, zn (Where n is the number of data points. ). Find the distances among all pairs of points and then display the pair of points having the minimum distance as given by the formula
Distance = Sqrt [ (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 ]
import java.util.Scanner;
import java.lang.*;
public class Distance
{
double dist[] = new double [10];
double d;
int count=0;
double x1, x2, y1, y2, z1, z2;
double min;
public void distance(double xx1, double yy1, double zz1, double xx2, double yy2, double zz2)
{
dist[count] = Math.sqrt( ((xx1-xx2)*(xx1-xx2)) + ((yy1-yy2)*(yy1-yy2)) + ((zz1-zz2)*(zz1-zz2)) );
System.out.println("The distance between the two points is (" + xx1 + "," + yy1 + "," + zz1 + ") (" + xx2 + "," + yy2 + "," + zz2 + ") = "+ dist[count] + " .");
if(count>0)
{
if(dist[count]<dist[count-1])
{
min=dist[count];
x1=xx1;y1=yy1;z1=zz1;x2=xx2;y2=yy2;z2=zz2;
}
}
else
{
min=dist[count];
x1=xx1;y1=yy1;z1=zz1;x2=xx2;y2=yy2;z2=zz2;
}count++;
}
public static void main(String[] args)
{
double x[][] = new double [10][10];
double y[][] = new double [10][10];
double z[][] = new double [10][10];
int no,temp=0;
Scanner scan = new Scanner (System.in);
System.out.println("Enter the number of points : ");
no = scan.nextInt();
for(int i=0; i<no; i++)
{
for(int j=0; j<3; j++)
{
System.out.println("Enter the x coordinate for point: "+ i + " " + j);
x[i][j] = scan.nextDouble();
}
}
Distance obj = new Distance();
for(int i=0; i<no-1; i++)
{
for(int j=i+1; j<no; j++)
{
obj.distance(x[i][0],x[i][1],x[i][2],x[j][0],x[j][1],x[j][2]);
}
}
System.out.println("The Shortest distance between the two points is (" + obj.x1 + "," + obj.y1 + "," + obj.z1 + ") (" + obj.x2 + "," + obj.y2 + "," + obj.z2 + ") = "+ obj.min + " .");
}
}
Click Here to Download
import java.io.*;
import java.util.*;
public class FrequencyOfWords
{
public static void main(String[] args)
{
System.out.print("\nEnter Some Text:");
Scanner input=new Scanner(System.in);
String text = input.nextLine();
String ans = "";
do
{
System.out.print("\nEnter A Word You Want To Verify The Frequency:");
String word = input.nextLine();
int count = 0;
StringTokenizer st = new StringTokenizer(text);
while (st.hasMoreTokens())
{
if (st.nextToken().equals(word))
{
count++;
}
}
System.out.println("\nFrequency of \"" + word + "\" is " + count + " times");
System.out.print("\nDo You Want Verify The Frequency Of One More Word[Y/N]:");
ans = input.nextLine();
} while (ans.equals("Y") || ans.equals("y"));
}
}
Click Here to Download
Write a program to store coordinates ( x, y, z) for data points in 3 Dimensional space. Prompt for how many points to consider and then collect the coordinates as x1, y1, z1, x2, y2, z2, ........ xn, yn, zn (Where n is the number of data points. ). Find the distances among all pairs of points and then display the pair of points having the minimum distance as given by the formula
Distance = Sqrt [ (x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2 ]
import java.util.Scanner;
import java.lang.*;
public class Distance
{
double dist[] = new double [10];
double d;
int count=0;
double x1, x2, y1, y2, z1, z2;
double min;
public void distance(double xx1, double yy1, double zz1, double xx2, double yy2, double zz2)
{
dist[count] = Math.sqrt( ((xx1-xx2)*(xx1-xx2)) + ((yy1-yy2)*(yy1-yy2)) + ((zz1-zz2)*(zz1-zz2)) );
System.out.println("The distance between the two points is (" + xx1 + "," + yy1 + "," + zz1 + ") (" + xx2 + "," + yy2 + "," + zz2 + ") = "+ dist[count] + " .");
if(count>0)
{
if(dist[count]<dist[count-1])
{
min=dist[count];
x1=xx1;y1=yy1;z1=zz1;x2=xx2;y2=yy2;z2=zz2;
}
}
else
{
min=dist[count];
x1=xx1;y1=yy1;z1=zz1;x2=xx2;y2=yy2;z2=zz2;
}count++;
}
public static void main(String[] args)
{
double x[][] = new double [10][10];
double y[][] = new double [10][10];
double z[][] = new double [10][10];
int no,temp=0;
Scanner scan = new Scanner (System.in);
System.out.println("Enter the number of points : ");
no = scan.nextInt();
for(int i=0; i<no; i++)
{
for(int j=0; j<3; j++)
{
System.out.println("Enter the x coordinate for point: "+ i + " " + j);
x[i][j] = scan.nextDouble();
}
}
Distance obj = new Distance();
for(int i=0; i<no-1; i++)
{
for(int j=i+1; j<no; j++)
{
obj.distance(x[i][0],x[i][1],x[i][2],x[j][0],x[j][1],x[j][2]);
}
}
System.out.println("The Shortest distance between the two points is (" + obj.x1 + "," + obj.y1 + "," + obj.z1 + ") (" + obj.x2 + "," + obj.y2 + "," + obj.z2 + ") = "+ obj.min + " .");
}
}
Click Here to Download
![]() |
No comments:
Post a Comment