I am trying to compute (360 / 24) / 60 I keep getting the answer 0.0 when I should get 0.25
In words: I want to divide 360 by 24 and then divide the result by 60
public class Divide {
public static void main(String[] args){
float div = ((360 / 24) / 60);
System.out.println(div);
}
}
This prints out:
0.0
Why is that? Am I doing something really stupid, or is there a good reason for this
As the title says it, I have a huge xml file (GBs)
<root>
<keep>
<stuff> ... </stuff>
<morestuff> ... </morestuff>
</keep>
<discard>
<stuff> ... </stuff>
<morestuff> ... </morestuff>
</discard>
</root>
and I'd like to transform it into a much smaller one which retains only a few of the elements.
My parser should do the following:
1. Parse through the file until a relevant element starts.
2. Copy the whole relevant element (with children) to the output file. go to 1.
step 1 is easy with SAX and impossible for DOM-parsers.
step 2 is annoying with SAX, but easy with the DOM-Parser or XSLT.
so what? - is there a neat way to combine SAX and DOM-Parser to do the task?
Can any one tell me what is the problem in my program?
String a[],b[];
int c[] = new int[b.length];
for (int j = 0; j < a.length; j++) {
for (int k = 0; k < b.length; k++) {
if (b[k].equals(a[j])) {
c[k]++;
} else {
c[k] = 0;
}
}
}
I have thousands of words stored in a HashMap. Now I want to check in every file that how many time one word occurred from allWords.
Can you point out mistake in my program or give me your idea that how I can do it?
Lets us take instances of two classes
public abstract class Shapes
{
public abstract void draw(Graphics g);
}
public class Rectangle extends Shapes
{
public void draw(Graphics g)
{
//implementation of the method
}
}
here the class Rectangle has extended class Shapes and implicitly it extends class Object.I know no other extension is possible but cant we call inheriting classes Shapes and Object multiple inheritance?(Since inheriting two classes is multiple inheritance from one perspective)
Hello,
Say i have
List<SomeObject> objList = new ArrayList<SomeObject>();
If someObject contains a field named id. Can we find it through some query like
objList.filter('id=2');
wihout looping through the list? If not, then why? This can be so useful method and used as an alternative to write tedious for loop?
Just a question that came to my mind so i thought i must clear it here :)
Thanks in advance :)
I am working on a recursive insertion method for a BST. This function is suppose to be a recursive helper method and is in a private class called Node. The Node class is in a class called BinarySearchTree which contains an instance variable for the root.
When I am trying to insert an element, I get a NullPointerException at :
this.left = insert(((Node)left).element);
I am unsure about why this occurs. If I understand correctly, in a BST, I am suppose to insert the item at the last spot on the path transversed. Any help is appreciated!
private class Node implements BinaryNode<E>
{
E item;
BinaryNode<E> left, right;
public BinaryNode<E> insert(E item)
{
int compare = item.compareTo(((Node)root).item);
if(root == null)
{
root = new Node();
((Node)root).item = item;
}
else if(compare < 0)
{
this.left = insert(((Node)left).item);
}
else if(compare > 0)
{
this.right = insert(((Node)right).item);
}
return root;
}
}
i am working on a webapp to download videos from streaming websites.
i don't know anything about applets but stuck here to know about them.
anybody please give basic detailed method to create such applet and how to use it?
Please see code snippet:
File[] additionalFiles = new File(FILE_PATH).listFiles();
boolean isDirectory = file.isDirectory();
I have verified that the directory path is correct, and when I run the code on Windows, the value of isDirectory is true (as it should be). Any suggestions as to why this occurs on Linux (RedHat Enterprise Linux)?
Why is it that
class swi22
{
public static void main(String[] args)
{
int a=98;
switch(a)
{
default:{ System.out.println("default");continue;}
case 'b':{ System.out.println(a); continue;}
case 'a':{ System.out.println(a);}
}
System.out.println("Switch Completed");
}
}
gives error as: continue outside of loop
I get headaches when I have to write nearly 10 lines of code to say 2 Objects are equal, when their type is equal and both's attribute is equal. You can easily see that in this way of writing the number of lines increase drastically with your number of attributes.
public class Id implements Node {
private String name;
public Id(String name) {
this.name = name;
}
public boolean equals(Object o) {
if (o == null)
return false;
if (null == (Id) o)
return false;
Id i = (Id) o;
if ((this.name != null && i.name == null) || (this.name == null && i.name != null))
return false;
return (this.name == null && i.name == null) || this.name.equals(i.name);
}
}
Hello All,
I have a following ArrayList,
[Title,Data1,Data2,Data3]
[A,2,3,4]
[B,3,5,7]
And I would like to convert this one like this,
[Title,A,B]
[Data1,2,3]
[Data2,3,5]
[Data3,4,7]
I'm bit confused with the approach. Any hint would be much appreciated.
Thanks.
I have following Class, I need to get type in constructor, how can I do that?
public abstract class MyClass<T> {
public MyClass()
{
// I need T type here ...
}
}
Arghh I just know people are going to hate me for asking this...
I was just playing around with inheritance and I noticed you can instantiate a subclass object in one of two ways when you write code. So then I wondered if there is any functional difference between these two methods. So in the code below, does this produce the exact same result...a MountainBike object, or is there some difference I should know about? Bicycle is the superclass for this example. If I do Bicycle bike or MountainBike bike I am effectively making a MountainBike due to new MountainBike()? So basically the difference is just semantics at this point?
Bicycle bike = new MountainBike();
MountainBike bike = new MountainBike();
in c or c++
function comlen is defined such
int comlen(char *p,char *q){
int i=0;
while *p && (*p++==*q++)
i++;
return i;
is this code equivalent of this function
int comlen(String s,String m){
int i=0;
while (i<s.length() && s.charAt(i)==m.charAt(i)){
i++;
}
return i;
?
please help
I wrote paging logic:
My requirement: total elements to display:100 per page,if i click next it should display next 100 records,if i click previous 100 records.
Initial varaible values:
showFrom:1,
showTo:100
max elements:depends on size of data.
pageSize:100.
Code:
if(p*emphasized text*aging.getAction().equalsIgnoreCase("Next")){
paging.setTotalRec(availableList.size());
showFrom = (showTo + 1);
showTo = showFrom + 100- 1;
if(showTo >= paging.getTotalRec())
showTo = paging.getTotalRec();
paging.setShowFrom(showFrom);
paging.setShowTo(showTo);
}
else if(paging.getAction().equalsIgnoreCase("Previous")){
showTo = showFrom - 1;
showFrom = (showFrom - 100);
paging.setShowTo(showTo);
paging.setShowFrom(showFrom);
paging.setTotalRec(availableList.size());
}
Here i can remove and add the elements to the existing data.above code works fine if i add and remove few elements.but if i remove or add 100 elements at a time counts are not displaying properly above code works fine if i add and remove few elements.
Why doesn't the following program return 0, since I am accessing p from a new A(), which has not had main called on it?
public class A {
public int p = 0;
public static void main(String[] args) {
p = Integer.parseInt(args[0]);
new B().go();
}
}
class B {
public void go() {
System.out.println(new A().p);
}
}
Is there a way to get an element id of a list to get it later through list.get(index)
when using
for(Object obj: o)
construction
Only define a local var and manually incrementing it?
Anything simpler?