下列java程序输出结果为_Java ,,以下程序的输出结果为答:

1、以下程序的输出结果为答:classA{doublex=10;protecteddoubley=12;}classBextendsA{inty=0;voidg(){intx=10;x=x+1;y=y+100;System.out.println("x="+x);System.out.println("y="+y...

1、以下程序的输出结果为答:

class A

{ double x=10;

protected double y=12;

}

class B extends A

{

int y=0;

void g()

{ int x=10;

x=x+1;

y=y+100;

System.out.println("x= "+x);

System.out.println("y= "+y);

}

}

class Example

{

public static void main(String args[ ])

{

B b=new B();

int y=-100;

b.g();

}

}

2、以下程序的输出结果为答:

class Area

{

float getArea(float r)

{

return 3.14f*r*r;

}

double getArea(float x,int y)

{

return x+y;

}

int getArea(int x,int y)

{

return x*y;

}

public classExample

{

public static void main(String args[])

{

Area a=new Area();

System.out.println("area1:"+a.getArea(100));

System.out.println("area2:"+a.getArea(2,1));

}

}

3、以下程序的输出结果为答:

import java.io.*;

public class abc

{ public static voidmain(String args[ ])

{ AB s= new AB("Hello!","I love JAVA.");

System.out.println(s.toString( ));

}

}

class AB {

String s1;

String s2;

AB( String str1 , String str2 )

{ s1 = str1; s2 = str2; }

public String toString( )

{ return s1+s2;}

}

4、以下程序的输出结果为答:

import java.io.* ;

public class abc

{

public static void main(String args[ ])

{ int i , s = 0 ;

int a[ ] = {10 , 20 , 30 , 40 , 50 , 60 , 70 , 80 , 90 };

for ( i = 0 ; i < a.length ; i ++ )

if ( a[i]%3 = = 0 ) s += a[i] ;

System.out.println("s="+s);

}

}

5、以下程序的输出结果为答:

publicclass Person {

String name;

intage;

public Person(String name, int age) {

this.name = name;

this.age = age;

}

publicstaticvoid main(String[] args) {

Person c = new Person("Peter", 17);

System.out.println(c.name + " is " + c.age + " years old!");

}

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值