The Artima Developer Community
Sponsored Link

Java Answers Forum
Whats wrong with this java code! can anyone help?

7 replies on 1 page. Most recent reply: Nov 18, 2004 7:04 AM by santhosh prasad

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 7 replies on 1 page
laura

Posts: 1
Nickname: loz20
Registered: Nov, 2004

Whats wrong with this java code! can anyone help? Posted: Nov 14, 2004 3:20 PM
Reply to this message Reply
Advertisement
class someprog
{
public static void main()
{
final int current;
int age;
System.out.println("How Old Are You This Year?");
age = EasyIn.getInt();
system.out.printLn("I think you were born in" + CURRENT-age);

EasyIn.pause("press <Enter> to quit");


}
}

this program prompts for the users age and then attempts to work out the year in which the user was born. but some thing is worng i cant get it to work! please help if you can thanks !


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Whats wrong with this java code! can anyone help? Posted: Nov 15, 2004 7:54 AM
Reply to this message Reply
1. To make a class executable, it must contain the following method:

public static void main (String[] parameters) {}

2. What is "CURRENT"? If you mean "current" you should write it.

3. You should use "System.out" instead of "system.out"

4. What class is EasyIn? This is not an error, I just don't know the class.

Karen

Posts: 11
Nickname: karry1412
Registered: Nov, 2004

Re: Whats wrong with this java code! can anyone help? Posted: Nov 16, 2004 3:38 AM
Reply to this message Reply
class somprog
{
public static void main (String args[])
{
final int current;
int age;
System.out.println("How Old Are You This Year?");
age = EasyIn.getInt();
System.out.println("I think you were born in" + current-age);

EasyIn.pause("press <Enter> to quit");


}
}

It still has one error:

variable current might not have been initialized
System.out.println("I think you were born in" + (current - age));

lalama fodie toure

Posts: 11
Nickname: lalama11
Registered: Nov, 2004

Re: Whats wrong with this java code! can anyone help? Posted: Nov 16, 2004 2:39 PM
Reply to this message Reply
Well you just need to do the right importation needed on your cod
start with import java.io.*;
and there's a throws IOEXception to do right here<public static void main(String[] arg) throws IOException{
then your code here }
what's the Easyin thing?

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Whats wrong with this java code! can anyone help? Posted: Nov 17, 2004 12:07 AM
Reply to this message Reply
For your 'current' problem:

Just initialize the variable.

final int current = 2004;

Amit

Posts: 23
Nickname: amitactsh
Registered: Nov, 2002

Re: Whats wrong with this java code! can anyone help? Posted: Nov 17, 2004 12:30 AM
Reply to this message Reply
> class someprog
> {
> public static void main()
> {
> final int current;
> int age;
> System.out.println("How Old Are You This Year?");
> age = EasyIn.getInt();
> system.out.printLn("I think you were born in" +
> rn in" + CURRENT-age);
>
> EasyIn.pause("press <Enter> to quit");
>
>
> }
> }
>
> this program prompts for the users age and then attempts
> to work out the year in which the user was born. but some
> thing is worng i cant get it to work! please help if you
> can thanks !

1> The signature of the main method is incorrect is should like this
public static void main(String[] arg)
2> The variable 'CURRENT' you used is in all small letter where you declared it but you are using all caps in a System.out.println statement that is incorrect.
3> 'S' of System.out.println must be a capital letter.
4> 'L' of System.out.println must be a small 'l'.
Java is case senstive.
5> It will be better if you provide the code for class EasyIn

toure

Posts: 2
Nickname: petert17
Registered: Nov, 2004

Re: Whats wrong with this java code! can anyone help? Posted: Nov 17, 2004 11:21 AM
Reply to this message Reply
check this out :
import java.util.*;
import java.io.*;
class someprog{
public static void main(String[] lalama)throws IOException{
Calendar now=Calendar.getInstance();
int current=now.get(Calendar.YEAR);
int age=Integer.pasreInt();
int y=current-age;
System.out.println("you were borne :"+y);
}
}

santhosh prasad

Posts: 1
Nickname: santhosh
Registered: Nov, 2004

Re: Whats wrong with this java code! can anyone help? Posted: Nov 18, 2004 7:04 AM
Reply to this message Reply
Argument is missing in main method

Ex: public static void main (String[] args)

Flat View: This topic has 7 replies on 1 page
Topic: help on Drawing Program Previous Topic   Next Topic Topic: how to (re)paint an AWT applet faster

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use