0

Help me to correct these codes

public class Program { String Name; int Age; double Height; static void Naitwa(String name){ System.out.println("Naitwa " + name); } static void age(){ Syetem.out.println("My age is 24 years old"); } static void height(){ System.out.println("i am 240cm"); } public static void main(String[] args) { Naitwa("Faridi Sadick"); mwana age = new mwana(); mwana height = new mwana(); age.age(); height.height(); } }

26th Jun 2017, 8:48 AM
Faridi Adidi Sadick
Faridi Adidi Sadick - avatar
3 ответов
+ 5
/* Better indenting your code could save your life ^^ ... and it's helpful for helpers ^^ */ public class Program { /* // you don't use these three variables String Name; int Age; double Height; */ static void Naitwa(String name) { System.out.println("Naitwa " + name); } static void age() { // Syetem.out.println("My age is 24 years old"); System.out.println("My age is 24 years old"); } static void height() { System.out.println("i am 240cm"); } public static void main(String[] args) { Naitwa("Faridi Sadick"); /* // what's the 'mwana' class object you are refering? // ... or what's your purpose by doing that?' mwana age = new mwana(); mwana height = new mwana(); */ // function declarations are in your main 'Program' class scope, so you can just call them without refering to an object name... // Anyway, you don't have any 'age' or 'height' variable previously declared/instanciated ('Age' and 'Height' are not the same variables, and handle number type of value, not object) // age.age(); age(); // height.height( // be carefull to good closing/ending syntaxe ;P height(); } }
26th Jun 2017, 9:53 AM
visph
visph - avatar
+ 2
firts.. you must create an instance of program class. Program p = new Program(); p.Naitwa("Faridi Sadick);//call your method p.age(); //call age method p.height;//call height method
26th Jun 2017, 8:59 AM
Sonny Michael
Sonny Michael - avatar
+ 2
hmm not quite sure how a post from 2 years ago.. showed up as most recent.. I hope he got his answer.. anyway... I did a snarky version in C#. :) hehehe https://code.sololearn.com/coV5WbSOf8eP
7th Apr 2019, 10:30 PM
laura