Last visit was: It is currently Thu Mar 28, 2024 8:19 am


All times are UTC-05:00




Post new topic Reply to topic  [25 posts ] 
Author Message
 Post subject:Java code help, please?
PostPosted:Tue Dec 11, 2007 6:55 pm 
User avatar
 

Joined:Sat Jun 03, 2006 3:51 am
Posts:1186
Website:http://griffinhart.livejournal.com/
Yahoo Messenger:Squall591
AOL:FinalWarrior591
Location:Look at my horse, my horse is amazing!
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.

_________________
"My word is my honor. My honor is my life."
-- Demonchild, Angelkin, the Blackest Seraph, the Final Warrior

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Tue Dec 18, 2007 1:56 am 
 

Joined:Mon Sep 17, 2007 5:57 pm
Posts:57
so much for no such simple way


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Tue Dec 18, 2007 2:52 pm 
User avatar
 

Joined:Sat Jun 03, 2006 3:51 am
Posts:1186
Website:http://griffinhart.livejournal.com/
Yahoo Messenger:Squall591
AOL:FinalWarrior591
Location:Look at my horse, my horse is amazing!
Yeah, pretty much. Stupid Java... C++ is much easier for me to use. cout >> " "; trumps System.out.println(" "); any day in my book.

-- Griffinhart

_________________
"My word is my honor. My honor is my life."
-- Demonchild, Angelkin, the Blackest Seraph, the Final Warrior

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Tue Dec 18, 2007 3:00 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
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.

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Wed Dec 19, 2007 9:42 pm 
User avatar
 

Joined:Sat Jun 03, 2006 3:51 am
Posts:1186
Website:http://griffinhart.livejournal.com/
Yahoo Messenger:Squall591
AOL:FinalWarrior591
Location:Look at my horse, my horse is amazing!
First, I always get those damn things backwards. Second, I know. I don't like using << endl;, I prefer "\n".

-- Griffinhart

_________________
"My word is my honor. My honor is my life."
-- Demonchild, Angelkin, the Blackest Seraph, the Final Warrior

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Thu Dec 20, 2007 12:59 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
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.

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Fri Dec 21, 2007 3:24 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
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.

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Sat Dec 22, 2007 12:00 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
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?

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Sat Dec 22, 2007 1:16 pm 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
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.

_________________
- Tycho

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Sat Dec 22, 2007 11:53 pm 
User avatar
 

Joined:Sat Jun 03, 2006 3:51 am
Posts:1186
Website:http://griffinhart.livejournal.com/
Yahoo Messenger:Squall591
AOL:FinalWarrior591
Location:Look at my horse, my horse is amazing!
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

_________________
"My word is my honor. My honor is my life."
-- Demonchild, Angelkin, the Blackest Seraph, the Final Warrior

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Sun Dec 23, 2007 3:33 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
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).

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Sun Dec 23, 2007 5:37 pm 
User avatar
 

Joined:Sat Jun 03, 2006 3:51 am
Posts:1186
Website:http://griffinhart.livejournal.com/
Yahoo Messenger:Squall591
AOL:FinalWarrior591
Location:Look at my horse, my horse is amazing!
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

_________________
"My word is my honor. My honor is my life."
-- Demonchild, Angelkin, the Blackest Seraph, the Final Warrior

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Sun Dec 23, 2007 11:32 pm 
User avatar
 

Joined:Sun Feb 12, 2006 8:56 pm
Posts:1019
Website:http://eddieringle.com
Location:Detroit, MI
I'm going to bed too. Night then. I'm looking forward to hearing from you.

_________________
-- Eddie Ringle

Check out Elysian Shadows and consider backing us on Kickstarter!

====================================

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Mon Dec 24, 2007 5:19 am 
User avatar
 

Joined:Sat Jun 03, 2006 3:51 am
Posts:1186
Website:http://griffinhart.livejournal.com/
Yahoo Messenger:Squall591
AOL:FinalWarrior591
Location:Look at my horse, my horse is amazing!
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

_________________
"My word is my honor. My honor is my life."
-- Demonchild, Angelkin, the Blackest Seraph, the Final Warrior

Image


Top
Offline  
 Post subject:Re: Java code help, please?
PostPosted:Mon Dec 24, 2007 5:52 am 
Literally Nine
User avatar
 

Joined:Sat Apr 02, 2005 3:31 pm
Posts:1171
Location:The vicinity of an area adjacent to a location.
Eclipse isn't a compiler, though, it's an IDE. For compiling Java, it uses the Java JDK's compiler, "javac".

_________________
- Tycho

Image


Top
Offline  
Display posts from previous: Sort by 
Post new topic Reply to topic

All times are UTC-05:00


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Theme created by Miah with assistance from hyprnova