Hi ! I want to write a java program that calculate age. What code do i need to use to let the user enter their birth year? (input method i think). Thanks
Printable View
Hi ! I want to write a java program that calculate age. What code do i need to use to let the user enter their birth year? (input method i think). Thanks
Sorry i'm kinda stupid since i'm a beginner but what is "scanner"? :D , It's not an assignment :D, i saw my teacher's example code and i want to write a program that is similar to it (since i fall way behind in my class), this is my teachers code:
But if you can explain to me how those red lines work then nevermind the assignment :D Thanks. please excuse my stupidityCode:[COLOR="Green"]import javax.swing.*;
public class Calculation{
public static void main(String []args){
[COLOR="Red"]new Calculation()[/COLOR];
}
public Calculation(){
Cube c= new Cube();
int i=5;
[COLOR="Red"] int squareIt = c.square(i);[/COLOR]
System.out.println(squareIt);
[COLOR="Red"]int cubeIt = c.cube(i);[/COLOR]
System.out.println(cubeIt);
}
}
class Cube{
public Cube(){}
[COLOR="Red"]public int square(int i)[/COLOR]{
return i*i;
}
[COLOR="Red"] public int cube(int i)[/COLOR]{
return i*i*i;
[/COLOR]}
}
Please edit your code above to use code tags. My signature below will explain this.
sorry ok i fixed it :D
What you're asking is how to call methods and constructors in Java, and the way to learn this is through your text books and notes. If you haven't found the Sun tutorials, please have a look as it will explain this better than any of us can:
Trail: Learning the Java Language (The Java™ Tutorials)
Best of luck!
Thanks alot