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

Pages: 1-4041-

Blue Pelican Java Project 11... please help

Name: Anonymous 2007-09-26 1:47 ID:AkvBcXjS

Write a program that will allow a user to input his name. The prompt and input data would look something like this:
Please enter your name. Peter Ustinov

Using a for-loop and the String method, substring(...), produce a printout of the reversal of the name.

For example, the name Peter Ustinov would be:
vonitsu retep

Notice that the printout is in all lower-case. Use the String method, toLowerCase() to accomplish this.

and btw this book can be downloaded here: http://www.bluepelicanjava.com/downloadBook_bpj.htm

Name: Anonymous 2007-09-26 1:48 ID:Heaven

NO EXCEPTIONS

Name: Anonymous 2007-09-26 1:53 ID:ozHvukxY

>>1
Where is your question? All I see is a problem so obvious that even you should be able to do it.

Name: Anonymous 2007-09-26 1:55 ID:MMFdP4d1

read SICP

Name: Anonymous 2007-09-26 2:45 ID:xVDfxoSl

``Java Project 11''? What were projects 1-10? Variations of ``Hello world''?

Name: Anonymous 2007-09-26 2:51 ID:nuYn6O2n

>>5
stop using faggot quotes

Name: Anonymous 2007-09-26 3:18 ID:AkvBcXjS

ok nvm

I got it

import java.io.*;
import java.util.*;
public class ClassOne
{
    public static void main (String args[])
    {
        Scanner kbReader=new Scanner(System.in);
        System.out.println("Enter your name.");
        String name=kbReader.nextLine();
        for(int j=0; j<name.length(); j++)
        {  
            name=name.toLowerCase();
            System.out.print(name.substring(name.length()-1-j, name.length()-j));
        }
    }
}

Name: Anonymous 2007-09-26 3:37 ID:WeYqFcnK

i like ur code, it makes sure the caps dont grow back, am i rite?

Name: Anonymous 2007-09-26 3:45 ID:tG9qr/sn

(print (reverse (read-line)))

Name: Anonymous 2007-09-26 5:19 ID:Heaven


perl -e 'print lc reverse scalar <STDIN>'

Name: Anonymous 2007-09-26 6:30 ID:KZhXWQg1

print ''.join(reversed(raw_input()))

Name: Anonymous 2007-09-26 6:35 ID:9zeGD6/Z

>>9
>>11
You forgot to lowercase it.

Name: Anonymous 2007-09-26 6:49 ID:KZhXWQg1

>>12
I just copied >>9. BTW, for some reason reversed object's str works like repr, but I suppose this is going to get fixed in Python 3000, and it'll become about as simple as Lisp: print(reversed(input())).

Name: Anonymous 2007-09-26 7:03 ID:fYW/k+2H

<?=strrev(strtolower(trim(fgets(fopen("php://stdin", "r"),128))));?>
lol php

Name: Anonymous 2007-09-26 8:45 ID:KZhXWQg1

>>14
It'd be even worse in C

Name: Anonymous 2007-09-26 8:55 ID:Heaven

print raw_input()[::-1].lower()

Name: Anonymous 2007-09-26 9:07 ID:Heaven

>>15
Can you explain me what is the meaning of `worse' in your sentence?

Name: Anonymous 2007-09-26 9:11 ID:mVKxgN3Q

Why not put   name=name.toLowerCase(); outside the for-loop so it don't have to be evaled every spinn of the loop moron.

Name: Anonymous 2007-09-26 9:17 ID:Heaven

ENTERPRISE.

import java.io.*;
import java.util.*;

public class ClassOne
{
    public static void main (String args[])
    {
        Scanner kbReader = new Scanner(System.in);
        System.out.println("Enter your name.");
        String name = kbReader.nextLine().toLowerCase();

        for (int j=name.length()-1; j>0; j--)
            System.out.print(name.charAt(j));

        System.out.println();
    }
}

Name: Anonymous 2007-09-26 10:35 ID:Heaven

>>19
It has to run for char 0 as well.

Name: Anonymous 2007-09-26 10:36 ID:KZhXWQg1

>>16
That's right, I always forget about the third extended slice prameter.

>>17
Stupid data type definitions, stupid string handling, stupid verbose int main().

Name: Anonymous 2007-09-26 10:54 ID:Heaven

>>21
Stupid data type definitions, stupid string handling, stupid verbose int main().
You fail, C is bad for other reasons.

Name: Anonymous 2007-09-26 11:20 ID:GXTx9atx

I'd say stupid string handling is a pretty big one.

The type system could definitely use an improvement.

An opt-in GC would be nice too, but that's heresy.

Name: Anonymous 2007-09-26 11:23 ID:Heaven

>>23
An opt-in GC would be nice too, but that's heresy.
exactly. use some other language if you want a GC.

I'd say stupid string handling is a pretty big one.
What is wrong with the standard string handling? There are always 3rd party libraries like TRE.

The type system could definitely use an improvement.
elaborate

Name: Anonymous 2007-09-26 11:33 ID:GXTx9atx

exactly. use some other language if you want a GC.

Yes, but what if I want to use C? Just without handling free?

I'm not aware of any language that's just C with a GC, unless I use C++ like C and use Boehms.

What is wrong with the standard string handling?

Null termination.

There are always 3rd party libraries like TRE.

Call me when it's the standard.

elaborate

It's verbose and weak. Why do the functional weirdos get all cool type systems?

Name: Anonymous 2007-09-26 11:34 ID:Heaven

Fuck. I hate Shiichan.

Name: Anonymous 2007-09-26 12:41 ID:Heaven

>>20
It does run for char 0. Are you retarded or what?

Name: Anonymous 2007-09-26 13:50 ID:Heaven

>>27
Because 0 > 0 amirite?

Name: Anonymous 2007-09-26 13:58 ID:Heaven

>>28
char 0 ends the string. By itself, it is an empty string. An empty string reversed and lowercased is still an empty string. >>19 does prints out that and terminates. What the fuck is your problem?

Name: Anonymous 2007-09-26 18:20 ID:Heaven

>>25
Yes, but what if I want to use C? Just without handling free?
Just use another langauge you fucking idiot.
If you don't like the features of a language do not use it.
Null termination.
Whoa.. actually wanting a library for C that does not depend from null terminator.. you're a fucking PHP programmer aren't you?
Call me when it's the standard.
Because having a huge standard library is awesome am i right?
It's verbose and weak. Why do the functional weirdos get all cool type systems?
Because C does not stand for Cool. C stands for hardCoded.

Name: Anonymous 2007-09-26 18:52 ID:siosVzdr

>>22
Shitty strings and type system are two big reasons. And I was talking about the ones affecting this program alone, not everything that sucks about C.

>>24
What is wrong with the standard string handling?
Not again... Murk loar.

elaborate
Python, lol

>>29
Yes, that's *EXACTLY* the problem.

>>30
Whoa.. actually wanting a library for C that does not depend from null terminator.. you're a fucking PHP programmer aren't you?
No, you're the fag. Also, binary unsafe strings aren't the only bad thing about C strings. Others are lack of Unicode (wchar_t? mbstombwhatever? That's a joke!), O(n) strlen (an important caveat) and other operations, shitty quality functions such as strcpy, strtok, etc., what else do you want? Pretty much every bit of C strings is made of shitty and failure, and part of it is spiced with a "rape my stack" flavour.

Because having a huge standard library is awesome am i right?
Yes, exactly. It makes things useful and portable.

Because C does not stand for Cool. C stands for hardCoded.
C also stands for "hard coded", as well as crappy, cumbersome and crude. I wish it stood for Cudder instead.

Name: Anonymous 2007-09-26 19:10 ID:85t5OmBa

Clever. ' clearly can compete completely; could create creative caveats.

Name: Anonymous 2007-09-26 19:22 ID:Heaven

>>27,29

I'm crying right now.

Name: Anonymous 2007-09-27 3:36 ID:Heaven

>>33
Specifications schmecifications.

Name: Anonymous 2007-09-27 5:52 ID:i6p2HyC7

>>31
C is supposed to be portable assembly and it serves it's purpose very well.

Not again... Murk loar.
I do not need to murk loar, i've read that thread.
It's mostly opinions by people who never tried to learn or understand C.

Python, lol
Python is good for what it is, same applies for any language.

O(n) strlen
Any function that checks the length of a string is O(n). it cannot be less.
what you say? length() in std::string?
Well you know how length() operates.. a `string' holds it's size and when it gets resized, the size changes as well.
Therefore, length() is O(1).
``Ah'' you might think ``that means length() is so faster than strlen() correct?''
The answer is yes but the function that changes the `size' of the string when it resizes is O(n).
And if you found length() to be faster from your tests, consider the following

char buf[1024] = "Hello, ";
size_t n;
n = strlen(buf); /* n == 7 */
strcat(buf, "World\n"); /* where we should do strcpy(buf+n, ..) */
n = strlen(buf); /* we re-strlen the "Hello, " part. */

That does not happend in case of std::string and whatever resize operation it has.
So is C++'s std::string faster than C's? No. The above code is considered awful, with proper code it'd be of the exact same speed (in theory)
You think Haskell or Lisp or whatever language you came from is better? It might be in theory, but a lisp/haskell implementation cannot be faster than a C one. (If both implementations are perfectly implemented)
Because nothing is perfect, sometimes using lisp or haskell or python is faster; that's because it's harder to write shitty code or do a mistake or something redundant in such languages.

shitty quality functions like strcpy, strtok, etc.
strcpy and strtok shitty? Why is that? Also, what is `shitty'?
Don't go about array bound checks and null terminator crap, please.
Strings in C are terminated with a '\0'. Therefore any str*() function is not shitty.
One could claim the concept is shitty, but the functions are perfect.
If you don't like a certain implementation move to another, and if you can't find a decent one write one yourself.

Yes, exactly. It makes things useful and portable.
I will agree about the portability, it is a pain in C.
I often find myself spending hours to write portable code for a VT100 terminal and a pre-ANSI compiler. It's a pain; however having a huge library would not solve this problem. C is portable assembly, assembly is a pain.

what else do you want?
Well, let's see until now you mentioned
1) lack of proper unicode support -- a part of me agrees but i do not care
2) shitty quality functions -- you are wrong
3) binary unsafe strings -- you are wrong again, strings are terminated with '\0' what you are asking for does not make any sense.
4) portability problems -- shoulnd't be a problem with proper C. I'd complain about the time it takes to write proper C rather than the portability problems.

So you have only one valid point (unicode) everything else is either incorrect or not focused in the real problem.

You should spend some more time learning and writing C code, then you will realize C's real problems.

I'll await for your reply.

Name: Anonymous 2007-09-27 6:22 ID:hos2LVVd

>>35
YHBT YHL HAND

Name: Anonymous 2007-09-27 6:37 ID:Heaven

>>36
i know.. but still.

Name: Anonymous 2007-09-27 9:45 ID:SjXdbRaz

>>35
This is why we don't post /prog to Reddit :( . You had to go and explain me step by step why strlen can't be better and why length can't be compared... You're probably the same guy who explained that C strings are null terminated. You still haven't realized I'm criticizing their design - the very things you bother explaining as if I were learning C, not their implementation.

Name: Anonymous 2007-09-27 11:26 ID:Heaven

>>38
I'm not from reddit.
Alright, whatever, you don't like the language don't use it.

You're probably the same guy who explained that C strings are null terminated.
im >>22,25,30,35 in this thread.

Name: Anonymous 2007-09-27 13:16 ID:nT+xKl1i

Any function that checks the length of a string is O(n). it cannot be less.
Wow. That whole section there is a long parade of ignorance. It looks like you have yet to learn addition and subtraction.

Also, if you think C++'s std::string is somehow any good, you're a damn idiot. Definitely no experience. Maybe read comp.lang.c++.moderated a bit, this shit isn't news.

Don't go about array bound checks and null terminator crap, please.
Why not? It's a big problem, stone-age PDP-11 idiots to the contrary. OH SHIT SORRY, C IS PERFECT!!1!

One could claim the concept is shitty, but the functions are perfect.
They're perfect yet str* let buffer overflows happen. Right on, fucker..

Look, brat, I'm so sorry some of us disagree with you. Get a few more years of C under your belt and we'll talk again, okay? You claim to know C, but you don't know about these issues? Right!

Name: Anonymous 2007-09-27 13:22 ID:uhhj8YqU

>>40
lispfag

Name: Anonymous 2007-09-27 13:28 ID:i6p2HyC7

>>41
You're the C reddit fag aren't you? get the fuck out

>>40
brat
I'm probably older than you!
C++'s std::string is good
no it is not, i never said that did i?
long parade of ignorance
englighten me.
They're perfect yet str* let buffer overflows happen. Right on, fucker..
It's the code you wrote that allows it.
Get a few more years of C under your belt and we'll talk again, okay?
...

Name: Anonymous 2007-09-27 13:45 ID:nT+xKl1i

no it is not, i never said that did i?

So why compare a C character array to to std::string, and then say that's the way it is?

It's the code you wrote that allows it.

Right, because you are perfect. You never make mistakes. You should not use tools that make those mistakes less likely. In fact, you are an awesome hard-core assembly nerd; only weaklings let a language construct a stack frame.

The moment anybody makes an argument related to programmer discipline, their argument falls flat. Why? Because if a novice can make that mistake, so can an expert. It's a question of probability, and it will happen.

I prefer to use tools that make certain bugs impossible. The only reason for null-termination is because they were faster on PDP-11s; pascal-style are superior in every way except for some rare niche cases.

englighten me.
Okay:
The answer is yes but the function that changes the `size' of the string when it resizes is O(n).
Explain to me how a Pascal-style str.len is O(n)?

Concatenation has nothing to do with using len. They're orthogonal. How you conflate the two is beyond me.

If you want fast concatenation with Pascal strings, use exponential allocation. As a C programmer I'm sure you're aware of the whole "trade memory for speed" thing. And on a separate note there are also ropes?

And lastly, for your other example, take a gander at string slices. Of course, to get that you need a GC, which will never happen in C. Most C programmers are too busy being studly to use one of those.

Name: Anonymous 2007-09-27 13:49 ID:uhhj8YqU

>>42
C reddit fag
LOL who. Your imaginary adversary?

Name: Anonymous 2007-09-27 14:12 ID:NU5AkYZ4

Lol @ Cfag. This thread confirmed he's a 15 years old kid who uses inline assembly to write OMG OPTIMIZED shitty algorithms, and doesn't even understand the difference between length and concatenation, both of which by the way can be O(1) in better string systems.

Name: Anonymous 2007-09-27 15:21 ID:Heaven

>>45
Inline assembly > LISP.

He's 15 and can do things you can't even though you're probably 35. Shame on you.

Name: Anonymous 2007-09-27 15:57 ID:nT+xKl1i

>>46
Or, the more likely alternative, is that we've done assembly and moved on.

It's not the 80s and 90s, anymore. The main reason to write assembly nowadays is for SIMD or other instructions that are inaccessible to many languages.

Name: Anonymous 2007-09-27 16:14 ID:Heaven

>>47
lispfag

Name: Anonymous 2007-09-27 16:18 ID:Heaven

Contrary to assembly language, high level languages require pretty much zero skills, which is why they're discussed in beginner literature like SICP.

Name: Anonymous 2007-09-27 16:18 ID:C6puiDW2

>>46
No reason you can't put inline assembly in Lisp.

Name: Anonymous 2007-09-27 16:21 ID:NU5AkYZ4

>>47,49
I admit your trolling skills are meritorious

Name: Anonymous 2010-12-22 17:01

Name: Anonymous 2011-02-04 16:32

Name: Anonymous 2011-02-04 19:54

Name: Anonymous 2011-02-17 20:29

check my doubles

Name: Anonymous 2012-06-25 23:39

爄ࡉ‑‒桤ᖓԔ敉ᘠ坐䠅桩霥剢≉ࡤ挰针䠩儗钆œ焖唂蕳䅓失鐗ѳ䉳ԙՠ㢕࠶✅堀頔舠癵颖蜔煵霴␐䈥餗䐔㖕桰堙卧゘偐堂ক腃⦃杰吲厉墅䆘饧㌅䥁✑搨⠴ᥲ挂爄厃偑鉓䜦ᖇし䈘㤵栥劔桁⒔慁猈⌆敔Ɛᐲ⑐昃礤坣㉙䙒Ĕ䁒楄Ѩ饩㤥ኃ傃❈㔤堙錅茡餣⡂ԃ船衩聲䉅ʼnᐧ䔨ᐂ∳荩⑹㜩芓煶ᕇгᠳ鈕␤焨㜀ገ葈艐怤馕䤀㝘椳頱Ԕገ䝖皃Ɔ㈶㝓由䕙我葐牒䙧劘墅䤇㜡蜴䝘ၒ㈣̱攦攱慇䁤㙥劆薆ʖ霢ធ遡卡吲㑥ѵ儔剡ҁॗ奖獅⑗爷钃࠙蚅逡咆ងも㜄㡂锧堤葠螙剐⥔⌢ゕ餩阅䑦䡣蒇挗ၶᡉ褧餶Հဴ蠓鐈慈聸঒焣╦镓陡≩莐倆晄耲牰ɘ㌡㤇琖晔鞂➀袈ᅅ䊗㢇▂昢䚓蚙枉钖扵刈茰ᄤ䎁硉攥䅶㝵Ԕ㥗爃⚑ė͓撑撂露䕀爖隀舤扉㦉⍤⊉霑礤͇塷ၶᄥ舱萇䜀喆衔Ŕ㊈∈⤔ጁ搀̩怃ࡱ敨冇⚀聁┰䉰⤈

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