Hello everyone, this morning I came across this code, and I have absolutely no idea what that means, can anyone explain me what do these represent, ex:
public class MyClass<T>
...
some bits of code then
private Something<T> so;
private OtherThing<T> to;
private Class<T> c;
Thank you
I am very bed in recursion...
I need to convert a char[] array by using recursion loop only, into string.
Without using for(),while()... loops. For example if i have char array: a[0]='H', a[1]='e', a[2]='l',a[3]= 'l',a[4]= 'o',
it returns H e l l o.
What I doing wrong?
public String toFormattedString(char[] a)
{
int temp =a.length;
if (a == null)
return "null";
if (a.length == 0)
return "0";
if( a.length == 1 )
else if( a[0] == a[a.length] )
return toFormattedString (a[a.length -1])+a[a.length];
I have this code but it doesn't work:
jPanel1.add(jLabel1);
jPanel2.add(jButton1);
jPanel2.add(jButton2);
jPanel3.add(jPanel1,jPanel1.TOP_ALIGNMENT);
jPanel3.add(jPanel2,jPanel2.BOTTOM_ALIGNMENT);
setContentPane(jPanel3);
pack();
Please tell me why!
I'm making a basic text editor, and I have 2 methods the first one is triggered when a user click 'Open' and it prompts the user to pick a file and it opens the file fine. I just want to access the same file path which is in a variable in the method that is triggered when the user clicks save. My methods are public, Iv'e tried accessing it through a class, still no. Please help!
Code:
public void open(){
try{
//Open file
JFileChooser fc = new JFileChooser();
fc.showOpenDialog(null);
File file = fc.getSelectedFile();
String haha = file.getPath();
BufferedReader br = new BufferedReader(new FileReader(file.getPath()));
String line;
while((line = br.readLine()) != null){
text.append(line + "\n");
}
} catch (FileNotFoundException e){
e.printStackTrace();
}catch (IOException e){
}
}
public void save(){
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(file.filePath));
bw.write(text.getText());
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
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)?
A lead developer on my project has taken to referring to the project's toString() implementations as "pure cruft" and is looking to remove them from the code base.
I've said that doing so would mean that any clients wishing to display the objects would have to write their own code to convert the object to string, but that was answered with "yes they would".
Now specifically, the objects in this system are graphic elements like rectangles, circles, etc and the current representation is to display x, y, scale, bounds, etc...
So, where does the crowd lie?
When should you and when shouldn't you implement toString?
Should I point out that I am a begginer at this?
double averageMonthlyTemp() {
double[] amt = new double[52];
int sum = 0;
int index = 0;
for (int i = 0; i < temp.length - 1; i = i + 7) {
//where temp is an existiing
//previously initialized array
//of 365 elements, form 0 to 364
for (int j = 0; j < 7; j++) {
sum = sum + temp[i + j];
if (j % 7 == 6) {
double average = ((double) sum) / 7;
amt[index] = average;
index++;
sum = (int) 0;
}
}
}
return amt;
}
When I try to compile, I get an "incompatible types" error, with the "amt" at return amt marked in red. Does somebody know why?
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?
Hello,
I am trying to display the output as "1(10) 2(23) 3(29)" but instead getting output as "1 2 3 (10)(23)(29)". I would be grateful if someone could have a look the code and possible help me. I don't want to use arraylist.
the code this
// int[] Groups = {10, 23, 29}; in the constructor
public String toString()
{
String tempStringB = "";
String tempStringA = " ";
String tempStringC = " ";
for (int x = 1; x<=3; x+=1)
{
tempStringB = tempStringB + x + " ";
}
for(int i = 0; i < Group.length;i++)
{
tempStringA = tempStringA + "(" + Groups[i] + ")";
}
tempStringC = tempStringB + tempStringA;
return tempStringC;
}
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;
}
}
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 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
class Parent
{
private void method1()
{
System.out.println("Parent's method1()");
}
public void method2()
{
System.out.println("Parent's method2()");
method1();
}
}
class Child extends Parent
{
public void method1()
{
System.out.println("Child's method1()");
}
}
class test {
public static void main(String args[])
{
Parent p = new Child();
p.method2();
}
}
I'm confuse why does in Parent::method2() when invoking method1() it will cal Parents method1() and not Childs method1 ? I see that this happens only when method1() is private? Can someone explain me why ?
Thanks you.
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);
}
}
defined variable:
LinkedList list1=new LinkedList();
Object get() in list1 obtains a node of list1
Object remove() in list1 deletes a node of list1
count() is length of list1
for(int i=1;i<list1.count();i++){
if(list1.get(i).startsWith('"',0)) //Error here
list1.remove(i);
}
Error: cannot find symbol
symbol: method charAt(int)
location: class Object
how to fix this problem?
I would like to delete the node in list1 which starts with (").
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.
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 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 ...
}
}