+ 1
What is wrong with this code
14 Antworten
+ 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
}
}
+ 1
Btw code is awful :( difficult to read.. if u wish, I can rewrite it for you in a readable way.
0
yes if u can i will be thankful
0
i wanna challenge you 👊
0
you got this 👍
0
ok
0
my pleasure
0
yaa sure
0
i don't manage java
0
بصى إحنا ولاد بلد ، م الآخر لو تعرفى HTML ماشى
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.
0
let's make a group on Facebook for our [Egyptians cooder] حتي هيكون التواصل فيه اسهل
0
Hey ;) sorry for the delayed response. Here is how would I implement it:
https://code.sololearn.com/cS505UNAevKP/#java
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