LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2003, 10:42 PM   #1
Laptop2250
Member
 
Registered: Oct 2003
Posts: 131

Rep: Reputation: 15
Question Java does "age" or "Age" matter when declaring an Int??


Hey this is my code, stuff:

public class GMFnTFF
{public static void main (String []args)
{EasyReader r= new EasyReader ();
int age;
System.out.print ("Enter your name: ");
String name= r.readLine ();
System.out.print ("Enter your age: ");
String LineAge= r.readLine ();
int Age= Integer.parseInt (LineAge); ////here i tried doing age why
////doesnt that work? but Age does
System.out.print ("Enter your weight: ");
String weight1= r.readLine ();
double weight= Double.parseDouble (weight1);
System.out.print ("Greetings, "+name+". You are "+Age+" years old and you weight "+weight+" pounds.");
}
}



int Age works
int age doesnt

why? what does age do in java? I am using j2sdk1.4.2 using the simple compiler bluejay and i am new if you cant tell so try to explain it easily. thx

thanks in advance (ey, me crew do yourselves a fava and dont steal my program or else, ali g talk )

also, i was updating this code for the last 1/2hr or so, and i found out that when i would type in

String name= r.readLine ();

it would automatically print the line to the output, does this always happen auto or is there a way to save a string and not print it immediatly? thanks again in advance (also the ali g talk meant dont steal my code, lol)

Last edited by Laptop2250; 10-12-2003 at 11:07 PM.
 
Old 10-13-2003, 12:01 AM   #2
ksgill
Senior Member
 
Registered: Apr 2003
Location: Toronto, Canada
Distribution: Ubuntu Jaunty (9.04)
Posts: 1,044

Rep: Reputation: 45
Age and age are 2 different things because variables in java are case sensitive. age is just a variable and doesnt do anything in java.
String name= r.readLine ();
it doesnt print to output, it reads a line and saves it under a string name. ..looks like u just got started with programming.. I think you should read a good book if u want to learn java.
cool
 
Old 10-13-2003, 09:54 AM   #3
Laptop2250
Member
 
Registered: Oct 2003
Posts: 131

Original Poster
Rep: Reputation: 15
i try to make age a int, so your telling me all ints have to be lower case? i tried bge (lower case int) and that works, i guess i didn't understand, is age a reserved method(or something) like double?

also, String name= r.readLine (); saves a variable, but why does it print it to the output if i didn't ask it to. the output of this code is

Enter your name: Laptop2250
Enter your age: 2250
Enter you weight: 225
Greetings, Laptop 2250. You are 2250 years old and you weight 225 pounds.

the only thing i understand is that those strings/int/doubles should only appear in the last line (greetings) because i told the program to. why do the ints/strings/doubles appear other places?

thanks again
 
Old 10-13-2003, 12:34 PM   #4
orgcandman
Member
 
Registered: May 2002
Location: new hampshire
Distribution: Fedora, RHEL
Posts: 600

Rep: Reputation: 110Reputation: 110
Here's my code that works (I changed the EasyReader class because I have an older JVM)

I think the problem is areound the line that I've flagged with /* >>> */
I think, judging from your code, you had declared age as an int at line /* LINE REF A */ and then
re-declared it as an int on line /* >>> */ which is a nono...
PS: I also used System.out.println because it will cause the output stream buffer to flush() automatically. plus it adds a newline character.


Code:
import java.io.*;
import java.util.*;
import java.lang.String;

public class GMFnTFF{
    public static void main (String []args) throws IOException{
	BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
	/* LINE REF A */ int age;
	System.out.println("Enter your name: ");
	String name= r.readLine ();
	System.out.println("Enter your age: ");
	String LineAge= r.readLine ();
	/* >>> */ age = Integer.parseInt (LineAge);     // I used age and it worked :D
	System.out.println("Enter your weight: ");
	String weight1= r.readLine ();
	double weight= Double.parseDouble (weight1);
	System.out.println("Greetings, "+name+". You are "+age+" years old and you weight "+weight+" pounds.");
    }
}
Aaron
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to calculate file age ? "File xy is 2 days 3 hours old" fluppi Linux - Software 5 06-03-2013 10:27 AM
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 11:26 AM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 03:07 PM
Java error "Exception in thread "main" java.lang.StackOverflowError" nro Programming 1 09-04-2004 03:47 AM
I cannot use "java chat". Browser says plugin required "x-java-vm". jdruin Linux - Software 4 04-18-2004 05:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration