No one has voted on any posts yet. Votes from other community members are used to determine a member's reputation amongst their peers.
hi guys, I'm new to python and i can't seem to understand this one line of code right here: distance, coordinates = min([(someFunction(state, coordinates), coordinates) for coordinates in coordinatesList]) coordinatesList contains a list of paired coordinates (x,y). someFunction returns an int. My question is why isn't distance and coordinates contain … | |
Ok i've just starting learning css and html and i created a nav bar following a tutorial. HTML file--------------------- <div id = "wrapper"> <div id = "navmenu"> <ul> <li><a href="#">ITEM</a> <ul> <li> <a href = "#">items</a> </li> </ul> </li> </ul> <ul> <li><a href="#">ITEM</a> <ul> <li> <a href = "#">item</a> </li> … | |
public class QS { public static <T extends Comparable<? super T>> T[] quickSort(T[]array) { return doSort(array, 0, array.length - 1); } //some other methods................. public static void main(String [] args){ QS qs = new QS(); int [] nums = {4,7,23,1,2,45,23,11}; qs.quickSort(nums);//gives error } } I am getting an error in … | |
So i have a class that takes 2 generics types: public class Something<K,V>.... In another class, i'm trying to create an array of Something objects. how do i do this? i'm getting an error with this: Something <K,V>[] s = (K,V[]) new Object[size]; | |
serious noob question, but i'm following my android book and it is doing something with a class that extends list activity. is that a file that i have to create on my own, or is that provided once i create a new android project? i can't seem to find it. | |
i have a private Node class with a getValue() method that returns the Node's value which is of generic type. In another class i've tried doing this: T tempItem = null; ----also generic tempItem = currentNode.getValue(); I get a complier error unless I cast it like this: tempItem = (T) … | |
Re:
What should I write within a while loop that allows me to keep on divding a number by 2 until it meets certain conditions. for example while(condition) { //what should i write here to have a double that divides by 2 until it meets the condition. } | |
my program includes pictures and audio, do i have add that to my project and then create a jar file? or i just have to include the source file and that's it? | |
i'm trying to write a game that show a background and a player on screen simultaneously using 2 different classes. here are the relevant parts of the program, or at least i think [code]public WorkingTitle2(){ super("Working Title"); setSize(550,429); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); loadPictures(); loadSounds(); pp = new PaintP(); pb = new PaintB(); add(pb); … | |
i've made this little game but the image keeps on flickering. i've read about double buffering online, but i really don't know how to implement the code into my game. here's some of the source code from the constructor and paint method: [code] public Game(){ super("test"); setSize(495,429); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); try{ … | |
i am not saying that all of my jar files are not working. in fact, all of them do work so far except for this one game that i've made. it runs perfectly in my editor, but its jar file will not execute. i checked its MANIFEST.mf file and the … | |
i don't know what happened, but i was running an applet that i made on a webpage and it works fine. i have the latest JRE and i am running firefox 4. then i've made some changes to the applet, tested it, it works, and copy and paste the class … | |
[CODE]if(count == 4){ qFinal.enqueue(q.peek()); if(count3 == 0){ System.out.println(qFinal); break; } else{ sort(qFinal); } } [/CODE] this code is inside a while loop, and with the break statement, it should break out of the loop right? instead i think the program also executes the sort(qFinal) method b/c after it prints qFinal … | |
i am getting an error in this. basically it sorts a queue in abc order. [CODE]public class Queue2{ public static void main(String [] args){ LinkedQueue q = new LinkedQueue(); q.enqueue("d"); q.enqueue("v"); q.enqueue("b"); q.enqueue("a"); q.enqueue("d"); System.out.println(q); System.out.println("----------------"); sort(q); } public static void sort(LinkedQueue q){ LinkedQueue qFinal = new LinkedQueue(); int count … | |
this is a linked list based queue private class Node { String value; Node next; Node(String val, Node n) { value = val; next = n; } } public String dequeue() { if (empty()) throw new EmptyQueueException(); else { String value = front.value; front = front.next; if (front == null) … | |
this assignment has stomped me. i thought it about long and hard and can't imagine how would i edit the quicksort to sort an array-based queue object. i'm required to use an array-based queue class which has only 3 methods: enqueue(), dequeue(), and peek(). they're pretty self explanatory. i cannot … | |
ok i have this assignment which i'm just having problems with the iterator part of it. from the [B]ListType [/B]class, this is what i wrote: [CODE] public Iterator iterator(){ return new OrderedStringListTypeIterator(list); } [/CODE] this code is from the textbook which idk how they got theirs to work, but... [CODE]import … | |
[CODE]public static void fun(int x){ System.out.println(x); x--; if(x > 0){ fun(x); } System.out.println("returning " + x); } [/CODE] in the main class: fun(5); [U]output:[/U] 5 4 3 2 1 returning 0 returning 1 returning 2 returning 3 returning 4 --------------------------------------- what i don't get is how the print statement is … | |
ok i got this assignment, and i'm a bit confused about what this method is supposed to do. i have to create a "setLab" method and accept a Grade object (which is already done and provided). this is what i got so far: [CODE]public class CourseGrades{ private Grade [] grades … | |
ok so the program gets a list of numbers, and it counts how many times a number is entered. [CODE]for(int i = 0; i < numList.size(); i++){ for(int j = numList.size() - 1; j > i; j--){ if(numList.get(i) == numList.get(j)){ count++; numList.remove(j); } } System.out.println(numList.get(i) +" " + count); count … | |
[CODE] vowels = wordcount.vowelNum(); //counts the vowels consonants = wordcount.consNum(); //counts the consonants, this is not working properly. [/CODE] the consNum() method: [CODE] int length = word.length(); for(int i = 0; i < length; i++){ if(word.charAt(i) == 'a' || word.charAt(i) == 'u'|| word.charAt(i) == 'i'|| word.charAt(i) == 'e'|| word.charAt(i) == … | |
[CODE]for(int i = 0; i < floorNum; i++){ if(floorNum == 12){ continue; { statements; statements; statements; }[/CODE] ------------------- if there anything wrong with this statement? i've tried using a while loop and the continue statement would work and skip number 12, but this doesn't work. | |
this program just prints out prime number within the range of the for loop. however it doesn't print anything. [CODE] boolean prime; for(int i = 11; i < 100; i++){ prime = isPrime(i); //this method works as i tested it before if(prime){ System.out.println(i); } } [/CODE] everytime i run this … | |
Re:
I just dont know where to start on this. Can anyone lend me a hand? 4- Write a Java program to create the following array that hold the salaries of employees: 1550.8 2439.5 1800.75 2890.0 The company wants to give the employees a bonus of 30% of their initial salary, … | |
[CODE]System.out.println("what is your name? "); String name = kb.nextLine(); for(int i = 0; i < member2.size(); i++){ if(member2.get(i).equals(name)){ System.out.println(name + " is a member. "); break; } else{ System.out.println(name +" is not a member. "); break; } [/CODE] i did a system.out.println on the member2 arraylist (String arraylist) and it … | |
for example, i have a txt file that reads: number of items: 2 number of zombies: 3 .... i want to write a method that increments just the numbers, and leave the "number of items" and "number of zombies" alone. is there any way to do this? i can easily … | |
[CODE]else if(choice == 3){ System.out.println("what is your name? "); String name = kb.nextLine(); boolean x = Member.checkMember(name); System.out.println(x); } [/CODE] when i run this, it prints "what is your name?" and instead of waiting for me type in something, it just skips that part and go ahead and prints x. … | |
i wrote a program that calculates how many coins that a vending machine splits out and such, and it does work but i can't figure how it works. at the time, i was sure of the logic, but now i can't understand how this is possible. [CODE] change = (amountPaid … | |
[CODE]public static String strCap(String str){ //capitalizes the first letter of the string String newStr1 = str.replace(str.charAt(0), Character.toUpperCase(str.charAt(0))); int position = str.indexOf(". "); // looks for a period followed by a space while(position != -1){ newStr1 = newStr1.replace(newStr1.charAt(position + 2), Character.toUpperCase(newStr1.charAt(position + 2))); position = str.indexOf(". ", position+1); } return newStr1; … |