「java小明」java输入小明的考试成绩
本篇文章给大家谈谈java小明,以及java输入小明的考试成绩对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、JAVA中一个字段比如 name='小明','小黄','小李';怎么分开查
- 2、java:小明去超市买东西,所有买到的东西都放在了购物车之中,最后到收银台一起结账。你编出来了是吗求助
- 3、java题搭积木小明最近喜欢搭数字积木,一共有10块积木,每个积木上有一
- 4、java编码小明2016年收入10万元,以后每年增长15%,哪一年年收入将达到100万元
JAVA中一个字段比如 name='小明','小黄','小李';怎么分开查
//题目说的不明确,想单独提取出来每一个名字?还是什么意思呢?
//我把切割,和查找都给你标出来了,你看看吧,也不知道是不是你想表达的意思!
public class 切割 {
public static void main(String[] args) {
System.out.println("\n\t\t---------切割-------\n");
init();
}
private static void init() {
String name="小明,小黄,小李";
//切割!
String[] arr=name.split(",");
//切割完成遍历!
for (int i = 0; i arr.length; i++) {
System.out.println(arr[i]);
}
//抽查出现位置,这里注意,会算上逗号的位置索引的!
System.out.println("小明:出现在字符串中索引位置是:"+name.indexOf("小明"));
System.out.println("小黄:出现在字符串中索引位置是:"+name.indexOf("小黄"));
System.out.println("小李:出现在字符串中索引位置是:"+name.indexOf("小李"));
}
}
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题搭积木小明最近喜欢搭数字积木,一共有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编码小明2016年收入10万元,以后每年增长15%,哪一年年收入将达到100万元
package com.wyq.GetTheYear;
import java.util.HashMap;
import java.util.Map;
public class GetTheYear {
private static int salary =10;
private static int year =2016;
public static void main(String[] args) {
int year = getyear();
System.out.println("小明将在"+year+"年收入达到"+salary+"万元");
}
public static int getyear(){
MapInteger, Integer map = new HashMapInteger, Integer();
while (salary=100) {
map.put(year, salary);
salary *=1.15;
year++;
}
return year;
}
}
//输出结果:小明将在2036年收入达到108万元
关于java小明和java输入小明的考试成绩的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。
发布于:2022-11-22,除非注明,否则均为
原创文章,转载请注明出处。