import java.util.Scanner;
public class Test4{
private static double width;
private static double length;
private String perimeter;
private String area;
//
private Test4(){}
//
private void Test4(double width,double length){
this.width=width;
this.length=length;}
//set get
public void setwidth(double width){
this.width=width;}
public void setlength(double length){
this.length=length;}
public double getwidth(){
return this.width;}
public double getlength(){
return this.length;}
//
public double getperimeter(){
return (width+length)*2;}
public double getarea(){
return width*length;}
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入长方形的长");
length = sc.nextInt();
System.out.println("请输入长方形的宽");
width = sc.nextInt();
System.out.println("长方形的周长是:"+sc.perimeter()+"长方形的面积是:"+sc.area());
}
}
为什么输出不了?难道sc.perimeter()这样的格式不对吗?
java中怎么输出不了?
答案:4 悬赏:60
解决时间 2021-03-12 06:30
- 提问者网友:小姐请专情
- 2021-03-11 22:22
最佳答案
- 二级知识专家网友:寂寞的炫耀
- 2021-03-11 22:48
没有sc.perimeter()这种用法的,你这样写编译都通不过的。
System.out.println("长方形的周长是:"+(width+length)*2+"长方形的面积是:"+width*length);可以直接这样写,也可以直接调用你写的计算方法
System.out.println("长方形的周长是:"+(width+length)*2+"长方形的面积是:"+width*length);可以直接这样写,也可以直接调用你写的计算方法
全部回答
- 1楼网友:一池湖水
- 2021-03-12 01:34
int number=count;
system.out.plintln("请输入你的成绩" );
scanner sc = new scanner(system.in);
count = sc.nextint();
if(count>90&&count<100){
system.out.plintln(" 您的成绩为: 优秀" );
}
if(count>80&&count<89){
system.out.plintln(" 您的成绩为: 良好" );
}
if(count>70&&count<79){
system.out.plintln(" 您的成绩为: 中等" );
}
if(count>60&&count<69){
system.out.plintln(" 您的成绩为: 及格" );
}
if(count>0&&count<59){
system.out.plintln(" 您的成绩为: 不及格" );
}
纯手打啊,没用软件 求给分
- 2楼网友:一起来看看吧
- 2021-03-12 01:09
System.out.println("长方形的周长是:"+sc.perimeter()+"长方形的面积是:"+sc.area()); 改成getperimeter() 和 getarea() 请采纳
- 3楼网友:心与口不同
- 2021-03-12 00:20
函数调用错误,周长,面积可以再main里直接调用,main里面直接调用改成静态方法
注意输入的长和宽只能为整数
import java.util.Scanner;
public class Test4{
private static double width;
private static double length;
private String perimeter;
private String area;
//
private Test4(){}
//
private void Test4(double width,double length){
this.width=width;
this.length=length;}
//set get
public void setwidth(double width){
this.width=width;}
public void setlength(double length){
this.length=length;}
public double getwidth(){
return this.width;}
public double getlength(){
return this.length;}
//
public static double getperimeter(){
return (width+length)*2;}
public static double getarea(){
return width*length;}
public static void main(String[]args){
Scanner sc = new Scanner(System.in);
System.out.println("请输入长方形的长");
length = sc.nextInt();
System.out.println("请输入长方形的宽");
width = sc.nextInt();
System.out.println("长方形的周长是:"+getperimeter()+"长方形的面积是:"+getarea());
// System.out.println("长方形的周长是:"+sc.perimeter()+"长方形的面积是:"+sc.area());
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯