考试急求java答案

好心人给我找出这个答案吧1、输出n行n列的空心矩形(要求使用嵌套循环),当n=5时,运行结果显示如下:################2、设计Java程序假设有50瓶饮料... 好心人给我找出这个答案吧
1、 输出n行n列的空心矩形(要求使用嵌套循环),当n=5时,运行结果显示如下:
#####
# #
# #
# #
#####
2、 设计Java程序
假设有50瓶饮料,喝完3个空瓶可以换一瓶饮料,依次类推,请问总共喝了多少瓶饮料?
3、 设计Java程序,实现如下功能:
获取50个0至300之间的随机整数,并输出到屏幕上;
取出上面50个整数中的偶数,输出到屏幕上。
4、 编写一个Java应用程序,设计一个汽车类Vehicle,包含的属性有车轮个数wheels和车重weight。小车类Car是Vehicle的子类,其中包含的属性有载人数loader。卡车类Truck是Car类的子类,其中包含的属性有载重量payload。每个类都有构造方法和输出相关数据的方法。
展开
 我来答
zhengzhibo2008
2009-06-25 · 超过18用户采纳过TA的回答
知道答主
回答量:45
采纳率:0%
帮助的人:44.5万
展开全部
1:

public class Test1 {
public static void main(String[] args){
int n=5;
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(j==0 || j==n-1||i==0||i==n-1){
System.out.print("#");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}
2:

public class Test2 {
public static void main(String[] args){
int total=50;
int n=0;
int j=0;
for(int i=total; i>0; i--){
if(j==2){
j=0;
i++;
}else{
j++;
}
n++;
}
System.out.println("共喝了"+n+"瓶");
}
}

3:

public class Test3 {
public static void main(String[] args){
int[] arr = new int[50];
int j=0;
for(int i=0; i<50; i++){
int n = (int) (Math.random()*300);
System.out.println(n);
if(n%2==0){
arr[j++]=n;
}
}
System.out.println("偶数:");
for(int i=0; i<arr.length; i++){
if(arr[i]!=0){
System.out.println(arr[i]);
}
}
}
}

4:

public class Test4 {
public static void main(String[] args){

Vehicle v0 = new Vehicle();
v0.print();
Vehicle v1 = new Car();
v1.print();
Vehicle v2 = new Truck();
v2.print();
}
}

class Vehicle{
public Vehicle(){

}

int wheels;
int weight;

public void print(){
System.out.println("这是Vehicle");
}

}

class Car extends Vehicle{
public Car(){
super();
}
int loader;
public void print(){
System.out.println("这是Car");
}
}

class Truck extends Car{
public Truck(){
super();
}
int payload;
public void print(){
System.out.println("这是Truck");
}

}
jie2shuang
2009-06-25 · 超过30用户采纳过TA的回答
知道小有建树答主
回答量:146
采纳率:0%
帮助的人:93.5万
展开全部
太简单了都是些基本算法``不会的话``你就最好别学了 浪费钱
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
司寇稷wy
2009-06-25 · TA获得超过203个赞
知道答主
回答量:65
采纳率:0%
帮助的人:58.7万
展开全部
痛楼上看法一致。
何况一题才5分。。
这点你小气了。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
OwenMolsg
2009-06-25 · TA获得超过472个赞
知道小有建树答主
回答量:216
采纳率:0%
帮助的人:266万
展开全部
自己想想挺简单
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
郜良御博超
2013-06-02 · TA获得超过3735个赞
知道大有可为答主
回答量:3058
采纳率:25%
帮助的人:187万
展开全部
1:
public
class
Test1
{
public
static
void
main(String[]
args){
int
n=5;
for(int
i=0;
i<n;
i++){
for(int
j=0;
j<n;
j++){
if(j==0
||
j==n-1||i==0||i==n-1){
System.out.print("#");
}else{
System.out.print("
");
}
}
System.out.println();
}
}
}
2:
public
class
Test2
{
public
static
void
main(String[]
args){
int
total=50;
int
n=0;
int
j=0;
for(int
i=total;
i>0;
i--){
if(j==2){
j=0;
i++;
}else{
j++;
}
n++;
}
System.out.println("共喝了"+n+"瓶");
}
}
3:
public
class
Test3
{
public
static
void
main(String[]
args){
int[]
arr
=
new
int[50];
int
j=0;
for(int
i=0;
i<50;
i++){
int
n
=
(int)
(Math.random()*300);
System.out.println(n);
if(n%2==0){
arr[j++]=n;
}
}
System.out.println("偶数:");
for(int
i=0;
i<arr.length;
i++){
if(arr[i]!=0){
System.out.println(arr[i]);
}
}
}
}
4:
public
class
Test4
{
public
static
void
main(String[]
args){
Vehicle
v0
=
new
Vehicle();
v0.print();
Vehicle
v1
=
new
Car();
v1.print();
Vehicle
v2
=
new
Truck();
v2.print();
}
}
class
Vehicle{
public
Vehicle(){
}
int
wheels;
int
weight;
public
void
print(){
System.out.println("这是Vehicle");
}
}
class
Car
extends
Vehicle{
public
Car(){
super();
}
int
loader;
public
void
print(){
System.out.println("这是Car");
}
}
class
Truck
extends
Car{
public
Truck(){
super();
}
int
payload;
public
void
print(){
System.out.println("这是Truck");
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(3)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式