「小明java好玩」8岁小朋友小明因为觉得好玩

博主:adminadmin 2022-12-07 19:27:08 58

本篇文章给大家谈谈小明java好玩,以及8岁小朋友小明因为觉得好玩对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java题目 小明左右手分别拿两张纸牌 黑桃10和红心8, 现在交换手中的牌 用程序模拟这一过程

交换牌的话只需:1.设一个中间变量赋值为左手中的纸牌10 2.把右手中的纸牌8赋值给左手中的纸牌10 3.把中间变量中的10赋值给右手中的纸牌8 就可以了

int j=10;左手中的纸牌

int k=8;右手中的纸牌

开始交换:

int i=j;

j=k;

k=i;

求解答Java编程 急 小明左右手分别那两张牌:黑桃十和红心八,现在叫还手中的牌,用程序模拟这一过程

class exchange{

public static void main(String arg[]){

String left="黑桃十";

String right="红桃八";

String temp=null;

System.out.println(“left=”+left+",right="+right);

temp=left;

left=right;

right=temp;

System.out.println(“left=”+left+",right="+right);

}

}

java题搭积木小明最近喜欢搭数字积木,一共有10块积木,每个积木上有一

package cn.itcast.day04.test;

import java.util.Arrays;

public class Sample1

{

    public static int ans = 0;

    public static void main(String[] args)

    {

        int[] arr = new int[10];

        int[] rest = new int[10];

        int[][] map =

        {

            {-1, -1}, {0, 0}, {0,0}, {1, 1}, {1, 2},

            {2 , 2}, {3 , 3}, {3, 4}, {4, 5}, {5, 5}

        };

        Arrays.fill(rest, 1);

        rest[0] = 0;

        dfs(arr, rest, map, 1);

        System.out.println(ans);

    }

    public static void dfs(int []arr, int[] rest, int[][] map ,int pos)

    {

        if(pos = 10)

        {

            ans += 1;

            return;

        }

        for(int i = 0; i != 10; ++i)

        {

            //没有被选择, 并且大于上面的积木

            if(rest[i] == 1  i  arr[map[pos][0]]  i  arr[map[pos][1]])

            {

                arr[pos] = i;

                rest[i] = 0;

                dfs(arr, rest, map, pos + 1);

                // 回溯

                rest[i] = 1;

            }

        }

    }

}

刚写 深搜 + 回溯,就能得出最终答案是 768.

java:小明去超市买东西,所有买到的东西都放在了购物车之中,最后到收银台一起结账。你编出来了是吗求助

public class ShopGoodsDemo {

public static void main(String[] args) {

ShopCar s1=new ShopCar(5);

s1.add(new EatFood("面包",12.1));

s1.add(new EatFood("辣条",2.4));

s1.add(new EatFood("饼干",22.3));

s1.add(new WashGoods("洗发水",32.5));

s1.add(new WashGoods("卫生纸",22.8));

print(s1.search("饼干"));

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

print(s1.getGoods());

}

public static void print(Goods gs[]){

double sum=0;

for(int i=0;igs.length;i++){

if(gs[i]!=null){

//System.out.println(p[i]+",");

System.out.println(gs[i].getName()+","+gs[i].getPrice());

sum=sum+gs[i].getPrice();

}

}

System.out.println("总价格为:"+sum);

}

}

public interface Goods {

public String getName();

public double getPrice();

}

public class EatFood implements Goods{

private String name;

private double price;

public EatFood() {

}

public EatFood(String name, double price) {

super();

this.name = name;

this.price = price;

}

@Override

public double getPrice() {

return this.price;

}

public void setPrice(double price) {

this.price = price;

}

public void setName(String name) {

this.name = name;

}

@Override

public String getName() {

return this.name;

}

}

public class WashGoods implements Goods{

private String name;

private double price;

public WashGoods() {

}

public WashGoods(String name, double price) {

super();

this.name = name;

this.price = price;

}

@Override

public double getPrice() {

return this.price;

}

public void setPrice(double price) {

this.price = price;

}

public void setName(String name) {

this.name = name;

}

@Override

public String getName() {

return this.name;

}

}

public class ShopCar {

private Goods goods[]=null;

private int foot;

//数组的大小由程序外部决定

public ShopCar(int len) {

if(len0){

goods=new Goods[len];

}else{

goods=new Goods[1];

}

}

//判断数组的内容是否已满,未满,则添加

public boolean add(Goods g){

if(this.footthis.goods.length){

this.goods[foot]=g;

foot++;

return true;

}else{

return false;

}

}

//关键字查找

public Goods[] search(String keyword){

Goods go[]=null;

int count=0;

for(int i=0;ithis.goods.length;i++){

if(goods[i]!=null){

if(this.goods[i].getName().indexOf(keyword)!=-1){

count++;

}

}

}

go=new Goods[count];

int f=0;

for(int i=0;ithis.goods.length;i++){

if(goods[i]!=null){

if(this.goods[i].getName().indexOf(keyword)!=-1){

go[f]=this.goods[i];

f++;

}

}

}

return go;

}

//得到全部信息

public Goods[] getGoods(){

return this.goods;

}

}

关于小明java好玩和8岁小朋友小明因为觉得好玩的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

The End

发布于:2022-12-07,除非注明,否则均为首码项目网原创文章,转载请注明出处。