How do you write a Java code to find number of duplicate words in a sentence?
As mentioned by others use String::split(), followed by some map (hashmap or linkedhashmap) and then merge your result. For completeness sake putting the code.
import java.util.*;
public class Genric<E>
{
public static void main(String[] args)
{
Map<String, Integer> unique = new LinkedHashMap<String, Integer>();
for (String string : "House, House, House, Dog, Dog, Dog, Dog".split(", ")) {
if(unique.get(string) == null)
unique.put(string, 1);
else
unique.put(string, unique.get(string) + 1);
}
String uniqueString = join(unique.keySet(), ", ");
List<Integer> value = new ArrayList<Integer>(unique.values());
System.out.println("Output = " + uniqueString);
System.out.println("Values = " + value);
}
public static String join(Collection<String> s, String delimiter) {
StringBuffer buffer = new StringBuffer();
Iterator<String> iter = s.iterator();
while (iter.hasNext()) {
buffer.append(iter.next());
if (iter.hasNext()) {
buffer.append(delimiter);
}
}
return buffer.toString();
}
}
Does Java support compile time binding?
interface A
{
void sh();
}
class B implements A
{
void show()
{
System.out.println("show");
}
public void sh()
{
System.out.println("Sh");
}
}
class C
{
public static void main(String...Aa) /* ??? */
{
A a1=new B();
a1.show();
a1.sh();
}
}
if i do that it show complie time error .then why ? can u explain
Add the last digit plus the sum of all the previous digits. The base case is that if your integer only has a single digit, just return the value of this digit.
You can extract the last digit by taking the remainder of a division by 10 (number % 10), and the remaining digits by doing an integer division by 10.
What is a getContentPane method in Java?
The getContentPane() method is used to get the main component in a Java Swing JFrame. It is usually a JPanel.
Can an identifier be used as a keyword?
As is used to import Module name as short short cut...
EX: import math as m
........Husnu
Is it possible to use the bubble sort algorithm to sort strings?
Bubble sort will be able to sort the items lexicographically, if you first assign the strings a relative value. The way strcmp in the C library does this is by returning the difference of the first different characters between the strings. For instance, if you call strcmp("Hello", "Highway"), strcmp will return 'e'-'i'. The ascii value of e on a unix system is 101 and the ascii value of i is 105, so it is returning the value 101-105 = -4 which will tell you that "Hello" is lexicographically smaller than "Highway". Doing this, you should be able to use any algorithm you want to sort the strings.
How do you add a click event to a java button?
we can do this using of javascript. you can use this following code:
<input type=button value="button" onClick=onclick_function()>
here onclick_function() is a function which is called by javascript on clicking the button. javascript code is as follows:
<script language="javascript" type="text/javascript">
// your code for onclick_function()
function onclick_function(){
alert("Welcome to javascript");
}
</script>
Convert the formula of Celsius to Fahrenheit in operator precedence in java?
import java.util.Scanner; public class Fahrenheit
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the temperature in Celsius scale"); double f= s.nextDouble();
double c;
c=(f-32)/1.8; System.out.println("Fahrenheit"); System.out.println( f);
}
}
What specifies a variable's name and data type?
Most programming languages require that you declare all of the variables that you intend to use in a program. A variable declaration is a statement that typically specifies two things about a variable:
* The variable's name
* The variable's data type
Posted by Special:Contributions
***EDIT***
This can be found on page 56 in "Programming Logic and Design" by Tony Gladdis
Why does a 1.8 GHz core 2 duo machine run at only 996 MHz?
Newer Intel processors incorporate something known as "SpeedStep." When the processor is not being used extensively, it downclocks itself to conserve power. You can disable this feature if it bothers you in your BIOS.
What are the two types of earnings management?
One type is simply conducting the business of the enterprise in order to attain controlled, disciplined growth. The other type involves deliberate manipulation of the accounting in order to create the appearance of controlled, disciplined growth
What method you would use to remove a selected object so that it is saved to the clipboard?
Ctrl + X or "Cut" from the object's context menu.
I would not say you're outta the woods yet, my dear. Try and avoid him and if he calls, politely hang up on him. Just say, "sorry, don't want to talk to you.
AnswerNarcissist are vindictive and rage. I never knew one to ostracize.Temporary ignoring is what they do, but they are in the same room so that they can monitor the pain they cause.Ostracising is what the victims usually do. They can't take the abuse so they cutoff and leave.narcs will hang around and stalk, and get revenge. If they have moved on, consider it a BLESSING. AnswerYes they do ostracise. They try to be more popular than you. For instance if you mention you like so and so and think they are great they will try one up man ship and say oh yea me and him are really good freinds even though they are not.They love to tell people "in a nice way" just how apthetic you are by making up fabricated stories. They do this to isolate you. They see other people as threats to their control. The victim often also will completely cut off contact to recover. Recovering from this type of person means cutting off all contact. AnswerIf he truly feels that you are no longer a source of narcissistic supply, you can count on never hearing from him again. In order to deny his narcissistic injury he must pretend that you never existed.Java program to solve lucky number?
Look at the definition, http://en.wikipedia.org/wiki/Lucky_number , then create an array of integers and start working on it. The sieve method requires you to eliminate certain numbers; you can either replace the eliminated array elements with a marker, or move the non-eliminated elements towards the beginning of the array (overwriting the eliminated elements), or perhaps copy to a different array - depending on whether you want simplicity in programming (putting a marker, such as 0, is probably easier to program), or efficiency.
Look at the definition, http://en.wikipedia.org/wiki/Lucky_number , then create an array of integers and start working on it. The sieve method requires you to eliminate certain numbers; you can either replace the eliminated array elements with a marker, or move the non-eliminated elements towards the beginning of the array (overwriting the eliminated elements), or perhaps copy to a different array - depending on whether you want simplicity in programming (putting a marker, such as 0, is probably easier to program), or efficiency.
Look at the definition, http://en.wikipedia.org/wiki/Lucky_number , then create an array of integers and start working on it. The sieve method requires you to eliminate certain numbers; you can either replace the eliminated array elements with a marker, or move the non-eliminated elements towards the beginning of the array (overwriting the eliminated elements), or perhaps copy to a different array - depending on whether you want simplicity in programming (putting a marker, such as 0, is probably easier to program), or efficiency.
Look at the definition, http://en.wikipedia.org/wiki/Lucky_number , then create an array of integers and start working on it. The sieve method requires you to eliminate certain numbers; you can either replace the eliminated array elements with a marker, or move the non-eliminated elements towards the beginning of the array (overwriting the eliminated elements), or perhaps copy to a different array - depending on whether you want simplicity in programming (putting a marker, such as 0, is probably easier to program), or efficiency.
What is a type as a term that relates to programming?
Computer programs store and handle data; this data can come in different types. For example, some languages define numeric types, which can further be subdivided into integers and floating-point numbers (i.e. numbers that don't accept decimals, and numbers that do), dates, boolean or logical data (can only contain the values "true" or "false"), strings (to store text or other symbols), and others.
Classes are a way to define additional (user-defined) types. Such user-defined types usually consist of several other data types. For example, you might decide that to store information about a point in space, you need three coordinates - 3 floating-point numbers, one for each of the 3 coordinates.
Which is the first non-comment statement in ajava program file?
It is most likely an "import Java. ...." statement. Which imports packages to be used in the source file. Or a class declaration "public class myClass { ".
A static block is a code block defined with the 'static' keyword and is not inside others blocks.
The static block is executed when the class is first loaded and the main purpose is perform all the initialization that may not be appropriate inside a constructor.
What Are The Differences Between Java And Python Variables Declaration?
You cannot declare a variable in Python without assigning some value to it. This is simply because a variable's type is inferred from the type of value that you assign to it.
a = "hello world" # a is a string
b = 42 # b is an integer
c = 3.14 # c is a float
d = [4, 8, 15, 16, 23, 42] # d is an integer array
In Java, all variable declarations must explicitly include a type even when declared with an initial value. The initial value, when given, must be of the same type or of a type that is covariant with the variable's type.
String a = "hello world";
int b = 42;
double c = 3.14
int[] d = {4, 8, 15, 16, 23, 42}
Note that local variables in Java that are declared but not assigned a value are considered "uninitialised". You must assign a value to all local variables before using them. Instance variables (members of a class) are always initialised. That is; numeric types have an initial value of zero, Boolean types are false and object references are null.
What is the command to compile a java program named Greetingsjava?
The command to compile a Java program is "javac", followed by the class name (file name).
How do you perform the xor operation for character in Java?
The XOR operator is the carat character: ^
Example:
// Create character
char ch = 'a';
System.out.println(ch);
// Perform XOR
ch = (char)(ch ^ 86);
System.out.println(ch);
// Perform XOR...again
ch = (char)(ch ^ 86);
System.out.println(ch);
Does the MacBook Air have java downloads?
Mac OS X (10.6.6 and higher) currently runs Java SE 6 version 1.6.0 26. This can be updated from Software Update found in the Apple menu.
public class Test {
public static void main(String[] args){
String str = new String("Rocky");
String str1 = "Rocky";
StringBuffer sb = new StringBuffer();
sb.append("Rocky");
String str2 = new String(sb);
}
}
Above are three commonly used ways of creating Strings. Apart from you you can also pass byte arrays and character arrays as arguments to the String constructor