• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

New to Board & Questions about 2 .java errs

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,

Let me first say I am just thrilled beyond no other beginning programmer's dream to find this forum! I had actually heard about this place when reading a the O'Reily's book "Head Start Java". I came across a section that mentioned the URL that had beem mentioned and had marked it down for a future visit. I can't recall the last name but I remember the first name was Kathy, sounded like a really sweet lady (and smart too!) from the description. Anyway.

I am a full time college student currently attending a beginners class in JAVA. As good as the class is, I'm not fully grasping certain concepts and that's frustrating to say the least. I've reached a point where I would like some solid feedback on where the improvements and my mistakes are being made rather than hearing this is wrong this is wrong, etc. I have to say when I started reading this reference book that directed me here it was the first time when I didn't feel totally useless or helpless if that makes sense. I'm a UNIX programmer by trade but to in my mind JAVA is like a cup of hot coffee right now. LOL! It's just a matter of breaking through that mental block first you know?

Ok, now to my questions. I'm currently working on a loop applet; the intent is for the user to enter a number 10 times. The number that is entered by the user is then displayed on the screen. EX: "You have entered: " When the user has entered 10 numbers, the highest number will then be shown to the user. EX: "The highest number is: "

Now I am showing 2 errors. I will be using 3 variables within the script. Now they all need to be declared at the beginning of the .java file correct?
For example...
public class Largest
{
// initializing variables in declarations
int counter = 1; // number counter
int number = 0; // number attempts entered
int largest; // result from user

// process 10 using counter controlled loop
while ( counter != 10 ) {

what I sort of understand is the if, else, while statement. But what I don't understand is don't you have to claim what is happening before you can clame the if else statement? Does that make sense or am I confusing myself??

I'll stop with my questions there so I don't get ahead of myself or get any more confused. Sorry so long but it's really good to be here and I look forward to chatting with everyone!

Sue
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

Kathy Sierra is indeed real nice. And purty. And so is her husband Bert. He's also nice, too, sometimes.

You asked if all the variables need to be declared at the top of "the script". In C, variables have to be declared at the top of a function, but that's not true in Java. In Java, you can just declare a variable right when you're gonna use it. That's often a good idea -- that big clump of declarations at the top of a function is just a hard to read mess, usually.

Now, about the if/else/before/after question: I think you are, in fact, just confusing yourself, because you sure are confusing me! If'n you want to spell your questions out a bit more, I'd be glad to help you untangle it, but as it stands, I don't know what you're getting at there.

Now, one more super important thing: real code that does sumpin' always goes inside a method, whether it's a public static void main(String[] argv) or something else. You've shown the start of a "while" loop outside of any method, and the compiler ain't gonna cotton to that, nohow.

Y'all come back real soon now, y'hear?
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic