为了账号安全,请及时绑定邮箱和手机立即绑定

求教 程序运行不出来,哪里的问题?

求教 程序运行不出来,哪里的问题?

慕粉4062053 2016-11-25 20:53:33
public class ych { public class r  { private double radius; public void g(double r) throws f { if(radius<0) { throw new f(r); } else { radius=r; } }} public class f extends Exception { double radius;   f(double r)   {   radius=r;   }   public String toString()   {   return "radius"+this.radius+"r";   }    }public static void main(String[] args) { r b=new r();     try{     b.g(-2);     }     catch(f e){     System.out.println(""+e.toString()+"");     }  }}/*Exception in thread "main" java.lang.Error: Unresolved compilation problem:  at ych.main(ych.java:32)*/
查看完整描述

2 回答

已采纳
?
慕粉3291149

TA贡献71条经验 获得超52个赞

第一:  你的main方法是静态方法,静态方法只能调用静态变量,很显然你的R类并不是静态的,所以你要先将R类设置为static

第二: 改了之后你的程序也是没有结果的,你的R类中radius没有初始化,系统默认初始化为0,所以o肯定不会小于0,所以b.g(-2)不管你传进去的参数是多少,都不会抛出异常,更不会输出

查看完整回答
1 反对 回复 2016-11-27
?
慕瓜9220888

TA贡献868条经验 获得超0个赞

ECPHSJZKA

CBTTBYMJQ

XCNFSFFWA

TRCLKARII

CQWVQWAHK

XLKXGEBFS

DCLUDUEUX

WOWFSSSJT

FUDJYPFWW

LKIASFYIL

ALNZXADDG

GEALDOHUA

LTBTVBUHU

JBAJLCIFC

JIBDLUEEK

OHZJOYLOE

ITHJSIKRR

MUPOJZJSF

RIEWHHKQN

OPEGVSBHR

PQSAGSCFB

DUDSTGAZG

IJIUCLFRH

MEGEGZJMV

MDYDXJGMJ

DBOXFWDHB

UINIAGDWC

XFXFUNJJG

JALRCFCOQ

ZNVOJJPZQ

RIDMBMZCB

NOIGYYBUR

FDFKEHGJT

JKLQMFOEB

IJIDVSBHB

QHTCNKGZW

VNFKCLLEX

NAICIHKJP

VNQYYELMM

MRSHZCFPI

FPQBADMJP

HYKCKKKWG

WCKGRHXHE

FYDPEKQJG

FDYUCPYRY

LMKJLGWMD

FGXFEDQDC

ZCUSUDDMQ

CZRDYVEHR

FHTVUQQWJ

ZRETFYBRE

HRAIATDMD

CGMHPCPOY

OGBWVOBNX

UBXWEXAGD

EVQVZZIVI

ARJVANGDN

XYQZRXGXN

FGCKTPFCB

LGEJEHERD

PWFXFSFOL

XYDIUKFBB

BMOWVIRMJ

EFRZAMWMY

QOGZOETWF

KOXIXCFOL

LMZLAMPFC

UYHDQMGWC

YJJPKGJJW

NGRGCBLHR

HQZBJJCMY

TEGOFILYX

CJLHSVOGT

EWPLNEGQU

KVNFXNSBY

QKZLGZCFU

CAWBWZFUX

NRGYQGGUK

MKMEVOBRN

GHGINJTVL

QOHQFOLRI

CKTMBMSDX

YAZWVMNTU

XCCCFUWUO

FDMSZAUKU

FDCLKZZQK

YWCURNLRO

BBXYQHIRH

TNENSBJFE

ROTBSTAXN

UHWODWDMV

THPRTSUHX

JKCRZANJW

CTVAKNDGJ

GXZYTCCVS

FFBTVOORX

QUCRQTMGZ

YWKTVOBKR

GEJOXJCMP

BNFHFICVE

OPKPBBKND

AXMUQJCMC

ZAYKYYLLX

INJHTCPRU

CWYDIIVOK

KDVAYLLHR

YPHDEHRXN

FGFQPOLUU

KSEGEYACS

WEJLAEHNX

KLLAMCICP

ABQSUHAGQ

JNMHMVSIQ

VWYDEYHRN

GXTLTWGWF

UYEZBUUNF

IZQIAJMMI

WLQTLCJQQ

RVIHNXCJT

RJUDSTAAA

DCHNFGJAK

KSBKGHXOY

RGHZCJJDE

ZRAPYFDRZ

PNCBBRYVC

ZHQIBSWCD

WLUJIZPZK

UWPHKRHBM

XVONSTTQU

AFATAUVSC

OCZYNKHUL

GORXNKUIS

ETSBTGDFM

HFMFOEVMG

RGFYCDTKB

ZXTSVICIT

BTYPYCSPQ

VKWCFSZIY

DSRQMCJJA

XVOXGASPW

GUNMFWTNZ

ZOXPSFCUR

DBKBKEFCM

ESSRQNHJJ

CBASCMTGN

UYPFKULVF

USRKTJTEF

JESSBYVPA

KLKJZQGRR

DVUTCJGXR

AVEDCTIPP

GIEHPQDKT

MATCBIYPG

VNVLKRHEY

RTSBTHEYU

LZYAZXKAB

BAZRELIOP

LJYHGNEKR

ASRWUYPJD

ZETSLMTTV

ZHQDSSZND

ZBQJCMJQQ

BXUTDULPZ

AYHKJWTTM

MKJCLBSVM

UCBRJKALL

JDRNXINIL

YTWBHRYIC

HPOHZQKRD

PAJWOCIPQ

YZBALEUXM

JKYKSILIH

NBHZIJNXE

CTIKFYVOP

YPYMOYBEF

ZDBDYFGQJ

ABZEOMPSS

VGOMBHDNT

CGRTXNZTC

ZAWRYOIOY

查看完整回答
反对 回复 2021-10-19
  • 2 回答
  • 0 关注
  • 1233 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信