What is wrong with this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
3rd Sep 2018, 9:34 PM
Nouran Waleed
Nouran Waleed - avatar
14 Answers
+ 1
import java.util.Scanner; public class Program { //public class rectangle(){ ////paramitarized constructor public Program (int l, int w){ //edited length =l; width=w; }////fields private int length ; private int width ; ////setters or mutators public void setlength(int l){ length =l; }public void setwidth(int w){ width=w; }/////geters or accessors public int getlength(){ return length; } public int getwidth(){ return width ; }////methods //calculate area public double calcarea(){ double a=length* (double) width ; //edited return a; } ///calculate premeter public double calpre(){ double p=2 * length* (double) width ; //edited return p; } public static void main(String[] args) { Scanner sc=new Scanner (System.in); System.out.println ("please enter length "); //edited int length =sc.nextInt(); System.out.println ("please enter width "); //edited int width =sc.nextInt(); Program s1= new Program (length,width); // moved and edited System.out.print ("rectangels area ==>" +s1.calcarea() ); // moved and edited System.out.print ("rectangels premeter==>" +s1.calpre() ); // moved and edited } }
3rd Sep 2018, 10:38 PM
Steppenwolf
Steppenwolf - avatar
+ 1
Btw code is awful :( difficult to read.. if u wish, I can rewrite it for you in a readable way.
3rd Sep 2018, 10:40 PM
Steppenwolf
Steppenwolf - avatar
0
yes if u can i will be thankful
4th Sep 2018, 7:00 PM
Nouran Waleed
Nouran Waleed - avatar
0
i wanna challenge you 👊
4th Sep 2018, 7:01 PM
Mostafa Zahw
Mostafa Zahw - avatar
0
you got this 👍
4th Sep 2018, 7:04 PM
Nouran Waleed
Nouran Waleed - avatar
0
ok
4th Sep 2018, 7:06 PM
Mostafa Zahw
Mostafa Zahw - avatar
0
my pleasure
4th Sep 2018, 7:09 PM
Nouran Waleed
Nouran Waleed - avatar
0
yaa sure
4th Sep 2018, 7:10 PM
Nouran Waleed
Nouran Waleed - avatar
0
i don't manage java
4th Sep 2018, 7:16 PM
Mostafa Zahw
Mostafa Zahw - avatar
0
بصى إحنا ولاد بلد ، م الآخر لو تعرفى HTML ماشى
4th Sep 2018, 7:16 PM
Mostafa Zahw
Mostafa Zahw - avatar
0
https://code.sololearn.com/ctfs6cJVsK1F/?ref=app make sure when you provide the inputs to povide them separated by newline for example 2 3 keep up the good work.
5th Sep 2018, 12:57 AM
amr
amr - avatar
0
let's make a group on Facebook for our [Egyptians cooder] حتي هيكون التواصل فيه اسهل
5th Sep 2018, 9:42 AM
Mohamed Ali
Mohamed Ali - avatar
0
Hey ;) sorry for the delayed response. Here is how would I implement it: https://code.sololearn.com/cS505UNAevKP/#java
6th Sep 2018, 2:35 PM
Steppenwolf
Steppenwolf - avatar
0
This is the modified code for more explanation just ask and i will show you why this line is wrong https://code.sololearn.com/cYpLxL7fCuF1/?ref=app
14th Sep 2018, 7:28 AM
‎خلاد سعد‎
‎خلاد سعد‎ - avatar