| | |
question
![]() |
If you can use it, Arrays.sort and return the last element. Otherwise, save the first value and compare it to the others always saving the larger value and then return that.
What part of all that are you having problems with?
What part of all that are you having problems with?
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Same concept, but just checking for equality.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Hi ronghel,
If I gave you a list of numbers and asked you which one was the biggest, how would you do that? (Not in code, just in life...)
For your second one, if I gave you a list of numbers and asked you if there were any duplicates in the list, how would you know?
For both just think about the steps you would take to solve each problem. Then worry about coding and testing after and it will be much easier
If I gave you a list of numbers and asked you which one was the biggest, how would you do that? (Not in code, just in life...)
For your second one, if I gave you a list of numbers and asked you if there were any duplicates in the list, how would you know?
For both just think about the steps you would take to solve each problem. Then worry about coding and testing after and it will be much easier
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. •
•
Join Date: Sep 2007
Posts: 30
Reputation:
Solved Threads: 0
java Syntax (Toggle Plain Text)
public class Problem8 { public static void main(String[]args) { int a=0; System.out.print(max(a)); System.out.println(); } public static double max(double[]x) { int a,b,c,d=0; double high=0; double [] check = {1,2,3,4,5,6,7,8,9}; for(a=0;a<check.length;a++) { if(check[a]>high) high=check[a]; } return x; } }
Last edited by Narue; Jan 10th, 2008 at 10:21 am. Reason: Added code tags
>public static double max(double[]x)
This signature suggests that you're supposed to pass an array of doubles to the function and the function returns the largest of them. Your code doesn't do that at all. Use this as your driver:
This signature suggests that you're supposed to pass an array of doubles to the function and the function returns the largest of them. Your code doesn't do that at all. Use this as your driver:
java Syntax (Toggle Plain Text)
public class Problem8 { public static void main(String[] args) { double[] check = {1,2,3,4,5,6,7,8,9}; System.out.println(max(check)); } public static double max(double[] x) { // Find the largest value in x and return it } }
I'm here to prove you wrong.
•
•
Join Date: Sep 2007
Posts: 30
Reputation:
Solved Threads: 0
java Syntax (Toggle Plain Text)
public class Problem7 { public static void main(String[] args) { int [] check = {1,2,3,4,5,6,7,8,9,10}; System.out.println(max(check)); } public static Boolean max(int[] c) { // returns true if the array a[] has any duplicate elements int high=0, b=0; for(int a=0;a<c.length;a++) { if(c[a]==c.length) System.out.print(c[a]); } return true; } }
Last edited by Narue; Jan 10th, 2008 at 1:31 pm. Reason: Added code tags
•
•
Join Date: Sep 2007
Posts: 30
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
import java.util.*; public class Problem7 { public static void main(String[]args); private static Random random = new Random(); { // *WILL I PUT DECLERATION HERE??** I DONT KNOW WHAT TO PUT HERE } public static boolean isSorted(int[] a) { // returns false unless a[0] <= a[1] <= a[2] <= a[2] <= . . . for (int i = 1; 1<a.length; i++) if (a[i] < a[i-1]) return false; return true; } public static void printed(int[] a) { // prints the elements of the specified array in sequence. if ( a == null | a.length == 0) return; System.out.print("{" + a[0]); for (int i=1; i<a.length; i++) System.out.print("," + a[i]); System.out.print("}"); } public static int[] randomIntarray( int length, int range) { // returns a new int array of the specified length whose elements // are randomly distributed in the range 0 to range-1; int[] a = new int[length]; for (int i=0; i<length; i++) a[i] = random.nextInt(range); return a; } public static int[] resized(int[] a, int length ) { // returns a new array with the specified length // containing the same elements as the specified array; int[] aa = new int[length]; int n = Math.min(a.length, length); System.arraycopy(a, 0, aa, 0, n); return aa; } public static void swap(int[] a, int i, int j) { // interchanges elements a[i] and a[j]; int ai=a[i], aj=a[j]; a[i] = aj; a[j] = ai; } Static Boolean hasDuplicates (int[] a) { // returns true if the array a[] has any duplicate elements } }
can someone try to explain this one...? coz i got always error when i try to run it..
![]() |
Similar Threads
- C command-line I/O question (C++)
- Apache Alias Directive... mod_alias question (Linux Servers and Apache)
- Completely new to C++ and have question about using char (C++)
- Question (Geeks' Lounge)
- question on cooling (Cases, Fans and Power Supplies)
- Context-sensitive grammar question :( (Computer Science)
- Welcome PC Mod Kingdom peeps! (Geeks' Lounge)
- Laptop LCD built into a car? (Monitors, Displays and Video Cards)
- Changing Network Configuration (*nix Software)
Other Threads in the Java Forum
- Previous Thread: j2me textfield password
- Next Thread: alignment
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows






