+ 1
Hi, how can i identify max between 10 number
max {1,2,3,4,5,6,...10}
3 Antworten
+ 5
if they are in array you can use
max=a[0];
for(i=0;i<a.length; i++){
if(max<a[i])
max=a[i];
}
remember this is not a copy past solution. You have to write rest of the code. I am sure you will it is easy
+ 2
hi,
please help me?
what is the problem?
public class Vehicle {
private String color;
private String module;
private int speed;
private double fuel;
Vehicle() {
this.setColor("red");
}
Vehicle(String c) {
this.setColor(c);
}
Vehicle(String m, int s){
this.speed = s;
this.module = m;
}
public String getColor() {
return color;
}
public void setColor(String c) {
this.color= c;
}
public String getModul() {
return module;
}
public void setModul(String m) {
this.module = m;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int s) {
this.speed = s;
}
public double getFuel() {
return fuel;
}
public void setFuel(double f) {
this.fuel = f;
}
public void bogh() {
System.out.println("beep");
}
Vehicle getfastercarmodule(Vehicle x){
if(this.speed > x.speed)
return this;
return x;
}
int getfastercar(Vehicle x){
if(this.speed > x.speed)
return this.speed;
return x.speed;
}
}
class Program {
public static void main(String [] args) {
Vehicle j;
Vehicle o;
j = new Vehicle("benz", 300);
o = new Vehicle("bmw", 250);
System.out.println("the faster car is"+" "+ j.getfastercarmodule (o).getModule());
System.out.println("the speed of car is"+ " "+j.getfastercar(o));
Vehicle car1 = new Vehicle();
Vehicle car2 = new Vehicle("green");
Vehicle car3 = new Vehicle();
System.out.println("the color for car1 and car3 is" + " " + car1.getColor()+ " " + "and the color for car2 is " + car2.getColor());
}
}
+ 1
you can also do the following:
int[] maxArray = {1,2,3,4,5,6,7,8,9,10};
int result = Arrays.stream(maxArray).max().orElseThrow(() -> new IllegalArgumentException("Wrong parameters!"));
System.out.println(result);