Java Pls Help!!!
Rusty's code works, here is a class with the code inside:
Code: Select all
public class Main {
/** Creates a new instance of Main */
public Main() {
System.out.println(reverse("Hello"));
}
public String reverse(String input){
if(input==null||input.length()==0)
return "";
String retval = "";
for(int i = input.length()-1;i>=0;i--)
retval += input.charAt(i);
return retval;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
new Main();
}
}
DFI LanParty X48 LT-2TR
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Intel Q9450 @ 3.2Ghz
Dell 24" 2408WFP | Phillips 37" 1080p
Sapphire HD4870 X2 2GB
4GB Corsair DDR-2 1066 | Thermalrite 120 Ultra Extreme | G9 Mouse | G15 Keyboard
Vista Ultimate x64
Reverse the elements in an array of n elements. When it is finished, the element at a[0] will be exchanged with a[n-1], a[1] exchanged with a[n-2], etc.
Another way to understand it better would be:
Hope this helps?
BTW. Rusty's code works!
Code: Select all
void reverse(int a[], int n) {
// function: Reverses the elements of a.
// parameters:
// a inout array of values.
// n in number of values in a, a[0]..a[n-1]
// returns: nothing
for (int i=0; i<n/2; i++) {
int temp = a[i];
a[i] = a[n-i-1];
a[n-i-1] = temp;
}
return;
}
Code: Select all
void reverse(int a[], int n) {
int head = 0; // index of first element
int tail = n-1; // index of last element
while (head < tail) {
int temp = a[head];
a[head] = a[tail];
a[tail] = temp;
head++;
tail--;
}
return;
}
BTW. Rusty's code works!
Ok thanks guys.
I am reading information in from a file the I want to insert something
I have this code so far
It sometimes works and sometime the words are in different orders and stuff
I am reading information in from a file the I want to insert something
I have this code so far
Code: Select all
public void Insert(){
int pos = Integer.parseInt(JOptionPane.showInputDialog("Please enter the position"));
for (int i = 0; i >= pos; i -- ){
strArr [i] = strArr [i -1];
}
strArr [pos] = JOptionPane.showInputDialog("Please enter the word you would like to insert");
size ++;
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...
Never mind guys dumb mistake on my part.
The int i = 0, it should be int i = size...
Man I must be fatiguing
After my IT exam today I realized that Eclipse is total trash. The pc i used froze every ten minutes and Eclipse bomed out so many times, i spent more time waiting for Eclipse to load than programming, no joke.
At home I use Netbeans is that the best free program available?
The int i = 0, it should be int i = size...
Man I must be fatiguing
After my IT exam today I realized that Eclipse is total trash. The pc i used froze every ten minutes and Eclipse bomed out so many times, i spent more time waiting for Eclipse to load than programming, no joke.
At home I use Netbeans is that the best free program available?
I am a guy so please people stop sending me these shady pm's and start playing computer games or bodybuilding. Forums aren't a good place to get chicks the gym is...