[英]how to find the smallest square surface for a specific city in array java
public clas Qyteti {
public float getSiperfaqja() {
return siperfaqja;
}
}
public clas Shteti {
Qyteti [] qytetet;
public void qytetiMeIVogel() {
}
}
This is my code, i created an obj array named qytetet My homework is to find the smallest city in array calculating by square surface.这是我的代码,我创建了一个名为 qytetet 的 obj 数组。 qytetiMeIVogel should to calculate the smallest square surface.
qytetiMeIVogel 应该计算最小的正方形表面。
qyteti = city
siperfaqja = square surface
There isn't really much to go on, but here is how I would do it:没什么可做的,但我会这样做:
public class City {
private int squareSpace[];
public void getData(){
Scanner sc = new Scanner(System.in);
squareSpace[] = new int[10];
System.out.println("Please enter the square spaces of 10 cities\n");
for(int i=0;i<10;i++) {
sqaureSpace[i]=sc.nextInt();
}
//sc.close();
}
public int findMin(){
int minValue=squareSpace[0];
for(int i=1;i<10;i++) {
if(squareSpace[i]<minValue)
minValue=squareSpace[i];
}
}
I have assumed a static value of 10 here, but you can go ahead and assume any value.我在这里假设静态值为 10,但您可以继续假设任何值。 Now all you need to do is call the getData() and findMin() wherever required.
现在您需要做的就是在需要的地方调用 getData() 和 findMin()。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.