计蒜客 泥塑课 java练习

本文是为了记录自己学习java过程的  才开始认真学java  代码可能写的比较挫  如果你是抱着学习的心态来看我的这篇博客  那我建议你去网上找找其他写的更好的人的~~



因为不熟悉这种语言  所以在做这道非常简单的题的时候也让我觉得很麻烦  

在这道题中我尝试用foreach方法来访问这个类数组的时候发生了错误  运行过程出错了  我不知道为什么 先留着这个问题吧  我至今还是不知道为什么

foreach方法遍历这个数组  然后我也没有改变数组中的内容  只是用来维护了一个最大值和最小值 

然后这道题其实可以在空间复杂度上进一步优化  简化掉所有数组  但是因为是为了熟悉语言来的 我并没有这么做~~~


当然如果你看到我的代码了 并且发现了我代码中写的有什么不好的地方 还请不吝赐教  万分感谢~~


点击打开链接  <-----------我尝试去读懂这个人写的代码 但是我并没有看懂 留着以后来改进这个代码的时候在看吧 

import java.util.*;
import java.io.*;
public class Main {
	public static void main(String[] args) throws Exception {
		Integer student_nums;
		Student[] Goods= new Student[200];
		Scanner cin = new Scanner(System.in);
		while (true) {
			student_nums = cin.nextInt();
			if(student_nums == -1)break;
		//	System.out.println("The value of stedent_nums is " + student_nums);
			for (int i = 0; i < student_nums; i ++) {
				Goods[i] = new Student(cin.nextInt() , cin.nextInt() , cin.nextInt(), cin.next(), i);
			}
		//	System.out.println("Here it is ~~~~");
			Integer maxx = -0x7fffffff, max_id = 0;
			Integer minn = 0x7fffffff, min_id = 0;
		/*	for (Student i : Goods) {
				if(i.value > maxx) {
					maxx = i.value;max_id = i.id;
				} 
				if (i.value < minn) {
					minn = i.value;min_id = i.id;
				}
				
			}*/
			for (int i = 0; i < student_nums; i ++) {
				if (Goods[i].value > maxx) {
					maxx = Goods[i].value;max_id = i;
				}
				if (Goods[i].value < minn) {
					minn = Goods[i].value;min_id = i;
				}
			}
			System.out.println(Goods[max_id].name + " took clay from " + Goods[min_id].name + ".");
		}
		
	}
}
class Student {
	Integer length;
	int id;
	Integer wide;
	Integer high;
	Integer value;
	String name;
	Student(Integer length , Integer wide, Integer high , String name,int id) {
		this.length = length; this.wide = wide;
		this.high = high; this.name = name;
		this.value = length * wide * high;
		this.id = id;
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值