TRENDING NEWS

POPULAR NEWS

How To Count Different Words In Java Programming Language

In java programming language, what is meant by "compound statement"?

Compound statements are statements that contain lists of statements enclosed in braces "{ statements }".

Examples : for, if,while, do..while, switch, functions, try..catch.

* The enclosed statements should be indented one more level than the compound statement.
* The opening brace should be at the end of the line that begins the compound statement; the closing brace should begin a line and be indented to the beginning of the compound statement.
* Braces are used around all statements, even single statements, when they are part of a control structure, such as a if-else or for statement. This makes it easier to add statements without accidentally introducing bugs due to forgetting to add braces.

How do I make 10 different random words in Java, and for none of them to repeat itself?

You can leverage on a Set capability and add to this set until the set size fit your needs (whih is 10 in your case). Set does not allow duplicate so if you push random words into it it will only accept the word that’s not in the Set yet.. And when the size of the Set reach your desired amount it will have n distinct words in it.. :)

If I know a programming language, am I considered bilingual?

No. Being bilingual means speaking, understanding, reading and writing another HUMAN language.
Mathematics also use a form of "language", but even with a Math degree, you are still not bilingual!

How do I print different words of a sentence in different lines in java?

Replace the space with a newline character.For eg:-String str = “hello world”;
System.out.println(str.replaceAll(“ “,”/n”));
The above code will convert the string “Hello World” to “hello/nWorld” and will print thishelloworldEdit:-Using loopString str="hello world";
for(String s :str.split(" ")){

System.out.println(s);

}

Java programming question?

Difficulty level = beginnerish intermediate

Scanner keyboard = new Scanner(System.in);

String sentence;
String[] senSplit;
int count = 0;
char[] wordToChar;
System.out.println("Enter a sentence with a period at the end:");
sentence = keyboard.nextLine();
System.out.println("All words with odd numbers of letters:");

senSplit = sentence.split(" ");
for (int i = 0; i < senSplit.length; i++)
{
wordToChar = senSplit[i].toCharArray();
if (wordToChar.length % 2 != 0 && wordToChar[wordToChar.length-1] != '.')
System.out.println(senSplit[i]);
else if (wordToChar.length % 2 != 0 && wordToChar[wordToChar.length-1] == '.')
{
if ((wordToChar.length-1) % 2 != 0)
{
wordToChar[wordToChar.length-1] = ' ';
System.out.println(String.valueOf
(wordToChar));
}
}
else if (wordToChar.length % 2 == 0 && wordToChar[wordToChar.length-1] == '.')
{
wordToChar[wordToChar.length-1] = ' ';
System.out.print(String.valueOf
(wordToChar));

Edit: Not printing duplicate of the same odd words.

Scanner keyboard = new Scanner(System.in);

String sentence;
String[] senSplit;
int count = 0;
char[] wordToChar;
System.out.println("Enter a sentence with a period at the end:");
sentence = keyboard.nextLine();
System.out.println("All words with odd numbers of letters:");

senSplit = sentence.split(" ");
for (int i = 0; i < senSplit.length; i++)
{
if (i > 0)
{
boolean flag = true;
for (int j = 0; j < i; j++)
{
if (senSplit[j].equals(senSplit[i]))
{
flag = false;
continue;
}
}
if (flag == false)
continue;
}
wordToChar = senSplit[i].toCharArray();
if (wordToChar.length % 2 != 0 && wordToChar[wordToChar.length-1] != '.')
System.out.println(senSplit[i]);
else if (wordToChar.length % 2 != 0 && wordToChar[wordToChar.length-1] == '.')
{
if ((wordToChar.length-1) % 2 != 0)
{
wordToChar[wordToChar.length-1] = ' ';
System.out.println(String.valueOf
(wordToChar));
}
}
else if (wordToChar.length % 2 == 0 && wordToChar[wordToChar.length-1] == '.')
{
wordToChar[wordToChar.length-1] = ' ';
System.out.print(String.valueOf
(wordToChar));

You need to import java.lang.*;

Another difficult problem word program in java?

write a grading program for each class with the following grading policies:

a. there are two quizzes, each graded on the basis of 10 points
b. there is one midterm exam and one final exam each graded on the basis of 100 points.
c. the final exam counts for 50% of the grade,the midterm counts for 25%. and the two quizzes
together count for a total of 25% (Do not forget to normalize the quiz scores. they should be
converted to a percent before they are average in. )any grade of 90 or more is an A.
any grade of 80 or more(but less than 90 is B,any grade of 70 or more(but less than 70) is a D,
and any grade of 60 or more (but less than 70) is a D. and any grade below 60 is an F. the program will
read the student's score and output the student's record,which consists of two quiz and two exam
scores as well as the student's overall numeric score for the entire course and final letter grade.

can somebody help me.. please i don't know if JOptionPane class is can be used here.

What is the Program to find frequency of words in sentence in Java?

I just googled with your title :DI found following solution that may you can use to find frequency of words in Java.public class Main
{
public static void main(String[] args)
{
String text = "the quick brown fox jumps fox fox over the lazy dog brown";
String[] keys = text.split(" ");
String[] uniqueKeys;
int count = 0;
System.out.println(text);
uniqueKeys = getUniqueKeys(keys);
for(String key: uniqueKeys)
{
if(null == key)
{
break;
}
for(String s : keys)
{
if(key.equals(s))
{
count++;
}
}
System.out.println("Count of ["+key+"] is : "+count);
count=0;
}
}
private static String[] getUniqueKeys(String[] keys)
{
String[] uniqueKeys = new String[keys.length];
uniqueKeys[0] = keys[0];
int uniqueKeyIndex = 1;
boolean keyAlreadyExists = false;
for(int i=1; i {
for(int j=0; j<=uniqueKeyIndex; j++)
{
if(keys[i].equals(uniqueKeys[j]))
{
keyAlreadyExists = true;
}
}
if(!keyAlreadyExists)
{
uniqueKeys[uniqueKeyIndex] = keys[i];
uniqueKeyIndex++;
}
keyAlreadyExists = false;
}
return uniqueKeys;
}
}
Output:the quick brown fox jumps fox fox over the lazy dog brown
Count of [the] is : 2
Count of [quick] is : 1
Count of [brown] is : 2
Count of [fox] is : 3
Count of [jumps] is : 1
Count of [over] is : 1
Count of [lazy] is : 1
Count of [dog] is : 1
Thank you :)

How can I write a Java program that asks the user for a word, and tells how many times that word occurs in the file and as well provides the line number?

I googled and got this :Counting number of words in a fileYou could have done that yourself

TRENDING NEWS