As the questions says... but here is a more practical example: Input: The generated numbers are: 175, 345, -567, 893, 100, -999, Output: The maximum number is 893 and the minimum is -999. The sum of the middle digits of max and mine is: 18
Basically the largest number 893 in this case, and the lowest -999 has a middle number of "9", 9+9 = 18 Im trying to understand how to pick out these two numbers (largest and smallest), but dont know how. I have done this:
public class Lab1_2 {
public static void main (String [] args) {
int tal1 = (int)(Math.random() *899+100) ;
int tal2 = (int)(Math.random() *899+100) ;
int tal3 = (int)(Math.random() *899+100) ;
int tal4 = (int)(Math.random() *899+100) ;
int tal5 = (int)(Math.random() *899+100) ;
int tal6 = (int)(Math.random() *899+100) ;
System.out.println(tal1 +" ");
System.out.println(tal2+" ");
System.out.println(tal3 +" ");
System.out.println(tal4+" ");
System.out.println(tal5+" ");
System.out.println(tal6+" ");
if (tal1<tal2 && tal1<tal3 && tal1<tal4 && tal1<tal5 && tal1<tal6){
System.out.println(tal1 + " is the smallest");
}
if (tal2<tal1 && tal1<tal3 && tal2<tal4 && tal2<tal5 && tal2<tal6){
System.out.println(tal2 + " is the smallest");
}
if (tal3<tal2 && tal3<tal1 && tal3<tal4 && tal3<tal5 && tal3<tal6){
System.out.println(tal3 + " is the smallest");
}
if (tal4<tal2 && tal4<tal3 && tal4<tal1 && tal4<tal5 && tal4<tal6){
System.out.println(tal4 + " is the smallest");
}
if (tal5<tal2 && tal5<tal3 && tal5<tal4 && tal5<tal1 && tal5<tal6){
System.out.println(tal5 + " is the smallest");
}
if (tal6<tal2 && tal6<tal3 && tal6<tal4 && tal6<tal5 && tal6<tal1){
System.out.println(tal6 + " is the smallest");
}
if (tal1>tal2 && tal1>tal3 && tal1>tal4 && tal1>tal5 && tal1>tal6){
System.out.println(tal1+" is the largest ");
}
if (tal2>tal1 && tal1>tal3 && tal2>tal4 && tal2>tal5 && tal2>tal6){
System.out.println(tal2+" is the largest");
}
if (tal3>tal2 && tal3>tal1 && tal3>tal4 && tal3>tal5 && tal3>tal6){
System.out.println(tal3+" is the largest ");
}
if (tal4>tal2 && tal4>tal3 && tal4>tal1 && tal4>tal5 && tal4>tal6){
System.out.println(tal4+" is the largest");
}
if (tal5>tal2 && tal5>tal3 && tal5>tal4 && tal5>tal1 && tal5>tal6){
System.out.println(tal5+" is the largest");
}
if (tal6>tal2 && tal6>tal3 && tal6>tal4 && tal6>tal5 && tal6>tal1){
System.out.println(tal6+" is the largest" );
}
}}
I think I need to do something like this: but dont know how to implement to specifik largest and smallest.
int svar1 = (var1 % 100 / 10);
int svar2 = (var2 % 100 / 10);