Ferrous Moon
http://www.ferrousmoon.com:80/forums/

Java code help, please?
http://www.ferrousmoon.com:80/forums/viewtopic.php?f=45&t=1094
Page 1 of 2

Author:  FinalWarrior [Tue Dec 11, 2007 6:55 pm ]
Post subject:  Java code help, please?

Yeah, yeah, yeah, I hate Java as much as the next C++ programmer, but since that's what AP Programming 2 (and 3) picks for its language of choice (rather than C++, like in Programming 1), I thought I'd get some practice.

Anyhow, I wrote up a little program that so far, uses two custom classes. However, the classes aren't the problem, it's input that's really pissing me off.

I'm using java.util.Random for input, and for the most part, it works fine, as long as I'm having the user input strings. As soon as I decide to input an integer, however, my program starts skipping lines of code because I.. cant'... clear... INPUT STREAM.

Anyone know how to do so for Java? In C++ it was something rather easy... getline(80, '\n') or something like that. My programming teacher tells me that there's no such simple way like that in Java (that she knows of).

-- Griffinhart

EDIT: Nevermind, got it all figured out. All I needed was an extra scan.nextLine() following the scan.nextInt() and I just had to blank out some variables.

Author:  gmt2001 [Tue Dec 18, 2007 1:56 am ]
Post subject:  Re: Java code help, please?

so much for no such simple way

Author:  FinalWarrior [Tue Dec 18, 2007 2:52 pm ]
Post subject:  Re: Java code help, please?

Yeah, pretty much. Stupid Java... C++ is much easier for me to use. cout >> " "; trumps System.out.println(" "); any day in my book.

-- Griffinhart

Author:  Tycho [Tue Dec 18, 2007 3:00 pm ]
Post subject:  Re: Java code help, please?

Quote:
Yeah, pretty much. Stupid Java... C++ is much easier for me to use. cout >> " "; trumps System.out.println(" "); any day in my book.

-- Griffinhart
You mean:
Code:
cout << " " << endl;
First, your streaming operators were backwards, second println prints the contents of the parentheses and a newline. cout << " "; would just put a space. No newline.

Author:  FinalWarrior [Wed Dec 19, 2007 9:42 pm ]
Post subject:  Re: Java code help, please?

First, I always get those damn things backwards. Second, I know. I don't like using << endl;, I prefer "\n".

-- Griffinhart

Author:  Tycho [Thu Dec 20, 2007 12:59 pm ]
Post subject:  Re: Java code help, please?

I've found that using \n instead of endl in tandem with cout causes major problems because endl causes the stream to flush, which never happens if you just use the \n character.

But I agree with you anyway, because I hate iostreams and anything that basically over-C++'s an application. Performance just goes down the drain with crap like this.

Author:  eddieringle [Fri Dec 21, 2007 3:24 pm ]
Post subject:  Re: Java code help, please?

And I believe that stdio is much smaller than iostream. So try using printf instead of cout for small projects if you want the sizes to stay small.
Code:
printf("Hello World!\n I'm not as fat as cout!\n Cout is %d\n", coutsize);
Hmm... did I get the variables right? I haven't coded in awhile, too much video games :D.

EDIT: Though I do find cout easier when using variables. :P And I use it when I don't care about the size of the program.

Author:  eddieringle [Sat Dec 22, 2007 12:00 pm ]
Post subject:  Re: Java code help, please?

Quote:
I don't want to understand Java better, because I freakin' hate the language and I never, ever, ever want to do another single damn program in Java ever the hell again. Sadly for me, next year is also Java programming. >.<

I mean, personally, I'd much rather stick with C++ (I dunno why I prefer it so much, I just do) or Python or Perl (those two I don't know whatsoever). I just have an inherent dislike of Java...

-- Griffinhart
Why not just ask the teacher if you can teach yourself C++ or a language you do like while the other kids learn Java?

Author:  Tycho [Sat Dec 22, 2007 1:16 pm ]
Post subject:  Re: Java code help, please?

Quote:
Why not just ask the teacher if you can teach yourself C++ or a language you do like while the other kids learn Java?
I prefer LOLCODE.
Code:
HAI CAN HAS STDIO? I HAS A VAR IM IN YR LOOP UP VAR!!1 VISIBLE VAR IZ VAR BIGGER THAN 10? KTHXBYE IM OUTTA YR LOOP KTHXBYE
For those of you in Rio Linda, this is a joke.

Author:  FinalWarrior [Sat Dec 22, 2007 11:53 pm ]
Post subject:  Re: Java code help, please?

Quote:
Quote:
I don't want to understand Java better, because I freakin' hate the language and I never, ever, ever want to do another single damn program in Java ever the hell again. Sadly for me, next year is also Java programming. >.<

I mean, personally, I'd much rather stick with C++ (I dunno why I prefer it so much, I just do) or Python or Perl (those two I don't know whatsoever). I just have an inherent dislike of Java...

-- Griffinhart
Why not just ask the teacher if you can teach yourself C++ or a language you do like while the other kids learn Java?
Because the class is "AP Programming 2 - Java". Not "AP Programming 2 - C++". That means that my AP exam (the exam that will earn me college credit for the class I'm taking in high school) will be on Java, and not C++. Which basically means I have to learn Java, or I'm just wasting my time in the class (and I'll be wasting $88USD on the exam).

And of course, I'm horrible at self-teaching myself abstract things. Tried it with physics and calculus... doesn't work. I can't learn from the book. Me needs an actual teacher to learn. (Which is why I hate it when people complain about copious amounts of notes... usually, they're complaining because they're lazy f***s. I, on the other hand, require notes and homework to learn.)

-- Griffinhart

Author:  eddieringle [Sun Dec 23, 2007 3:33 pm ]
Post subject:  Re: Java code help, please?

Eww! Icky MS tutorials? I could never learn anything from that.

The one and only site where I learned C++ the best was http://www.learncpp.com. IMO they have the best C++ tutorials on the web.

As for Java, I learned on the Sun website (not a lot, it got boring), and from Sam's Teach Yourself Java in 21 days. (The book is much more informative and interesting, it's kind of ironic :P).

Author:  FinalWarrior [Sun Dec 23, 2007 5:37 pm ]
Post subject:  Re: Java code help, please?

Yeah, learncpp is a pretty good site. Back when I still did C++, my teacher would refer me to that site if I had any problems with programs I was doing at home.

It's not so much that I have a hard time understanding the language, it's that I don't get some of the errors I get (logical/syntactical, not run-time), like the problem that was the reason for me posting this thread in the first place.

-- Griffinhart

Author:  eddieringle [Sun Dec 23, 2007 11:32 pm ]
Post subject:  Re: Java code help, please?

I'm going to bed too. Night then. I'm looking forward to hearing from you.

Author:  FinalWarrior [Mon Dec 24, 2007 5:19 am ]
Post subject:  Re: Java code help, please?

Jesus, do you even need that many compilers? I use MS Visual Studios for C++ and Eclipse for Java. (Mainly because those are the ones my school use, so they're more-or-less compatible... the school compilers are outdated as hell, though.)

-- Griffinhart

Author:  Tycho [Mon Dec 24, 2007 5:52 am ]
Post subject:  Re: Java code help, please?

Eclipse isn't a compiler, though, it's an IDE. For compiling Java, it uses the Java JDK's compiler, "javac".

Page 1 of 2 All times are UTC-05:00
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/