Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java

Name: Anonymous 2009-01-19 10:00

right /prog/ i've never used a text board on here, so, here goes. I would like a small hand with some basic java programming. I am using the BlueJ environment.

Given two Strings s1 and s2 already defined as

String s1 = "SESQUIPEDALIANISM";
String s2 = "";

write a sequence of lines of java code that will make String s2 contain (only)
the letters number 3, 10 and 12 from s1
(e.g. if s1 was "piano"
s2 containing letters 1, 3 and 4 would make s2 = "pan").

Name: Anonymous 2009-01-19 10:06

What's the point of this?  Sounds useless.

Name: Anonymous 2009-01-19 10:06

charAt(int index) returns the char at index. That's all you need to know.

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-19 10:09

In JavaScript its just : s2=s1[2]+s1[9]+s1[11];
(index at 0)

_________________________
orbis terrarum delenda est

Name: Anonymous 2009-01-19 10:20

In LIST COMPREHENSION–ORIENTED Python, it's just s2 = ''.join(s1[x] for x in (2, 9, 11))

Name: Anonymous 2009-01-19 10:24

>>5
let s2 = map (s1 !!) [2, 9, 11]

Name: Anonymous 2009-01-19 10:25

hmm, i believe what he meant was the he actually wanted to change s2 to contain letters 3, 10 and 12 from s1. Making it SAI? Please correct me if im wrong? IF so, would the charAt work for this? Im not sure.

Name: `Peyote` Simon Joints 2009-01-19 10:27

>>7
What is this ``change'' concept?  I am afraid I have never heard of such a concept.

Name: Anonymous 2009-01-19 10:28

>>7
IF so, would the charAt work for this? Im not sure.
Well, I'm pretty fucking sure that it will. If you don't know elementary Java, why post in this thread at all?

Name: Anonymous 2009-01-19 10:28

>>8
<interactive>:1:0: parse error on input ``'

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-19 11:17

>>5,6
This can be done in JavaScript too(using  small arrays is wasteful however):
var s2='sdiusadishdsf';
var sg1=[3,5,7];s1=''
for(i in sg1){s1[i]=s2[sg1[i]]};s1.join("")

_________________________
orbis terrarum delenda est

Name: Anonymous 2009-01-19 11:23

s/SESQUIPEDALIANISM/Now you have two problems./

Name: Anonymous 2009-01-19 11:26

public class SESQUIPEDALIANISMExtractorFactory {
}

Name: Anonymous 2009-01-19 13:08

s2=s1.toCharArray()[2]+s1.toCharArray()[9]+s1.toCharArray()[11];

Name: Anonymous 2009-01-19 14:24

>>14
uh...

Where's the factory?

Where are singletons?

Fucking newbies.

Name: Anonymous 2009-01-19 15:41

Java
BWAHAHAHAHAHAHAHA

Name: =+=*=F=R=O=Z=E=N==V=O=I=D=*=+= !FrOzEn2BUo 2009-01-19 16:23

>>15
An earthquake occurred and all the singletons are now trapped under the factory. Only an expert can save them!
Are an expert enough to save singletons?
_________________________
orbis terrarum delenda est

Name: Anonymous 2009-01-19 17:19

>>17
Fuck off.

Name: Anonymous 2009-01-19 19:29

>>15

/**
 * JAVA algorithm to solve cs100 homework problem.
 * @author Anonymous
 */

/* StringBuffer provides synchronization so this code can be executed
 * correctly by multiple threads. */
StringBuffer stringBuffer = new StringBuffer();

/* Construct the result string by concatenating substrings
   of s1. */
stringBuffer.append(s1.charAt(3-1));
stringBuffer.append(s1.charAt(10-1));
stringBuffer.append(s1.charAt(12-1));

/* Set the result to s2. */
s2 = stringBuffer.toString();

Name: Anonymous 2009-01-19 20:57

>>19
I lol'd

I don't know a while lot about Java, but, if the string is allocated on stack, then each thread has its own stack, so there's no need to global object to access, so no need to synchronize, if it's done via heap, then it's still a local variable to your function, so you wouldn't need to lock it, as no other code can access it(not even your function when running twice). You would only need to do this if you were editing a member of some class, and then, but then, you'd need to take extra precautions, which are not included in your code.

Have I been trolled?

Name: Anonymous 2009-01-19 22:04

Have I been trolled?
You seem to have forgotten, sir; This is /prog/.

Name: Anonymous 2009-01-19 23:45

>>20

I too lol'd. However, the faggot in >>19 got the "synchronization" aspect wrong, but using StringBuffer is a good idea because string are immutable (as in their would be 5 string allocated for the program). And even though these conditions are known at compile time I highly doubt any JVM or compiler would be smart enough to optimize that.

If you used immutable stings in .Net, it would optimize to not to the excessive allocations.

Name: Anonymous 2009-01-20 0:01

>>22
The + operator in Java is typically converted by the compiler to StringBuffer anyway (or more likely StringBuilder, since you're using a 1.5+ JVM). So most uses of + are already append() calls. You'll only run into performance problems when you start reassigning String references (since the bytes of the string's old value must be garbage collected). And finally, arguing about asymptotic runtime is irrelevant when the OP's example only involves three concats.

Name: Anonymous 2009-08-16 23:15

Lain.

Name: Anonymous 2010-12-17 1:29

Xarn is a bad boyfriend

Don't change these.
Name: Email:
Entire Thread Thread List