I believe i have the basics of what I want to do down. I'm just having trouble working oy the kinks of the problem.I cant figure out what to do or where to even start attempting to figure it out. I dont know how to get "bigNumber" and "littleNumber" resolved to a variable and I'm also getting i can't convert float to int but thats not even my intention. I'm just having trouble understanding what I'm doing wrong.
import java.util.Scanner;
public class Maxmin {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter " number.length " values");
float number = input.nextFloat();
double max = number;
}
public static float bigNumber (float max) {
double max1 = bigNumber[0];
for (float f = 1; f < bigNumber; f ) {
if(bigNumber[f] > max1) max1 = bigNumber[f]; }
}
public static float littleNumber (float min) {
double max = littleNumber[0];
float indexOfMax = 0;
for (float i = 1; i < littleNumber; i ) {
if(littleNumber[f] > max) {
max = littleNumber[f];
indexOfMax = i;
}
}
}
}
this is what I have. I tried to to fix as many bugs as I can, but i'm just lost.
CodePudding user response:
base on my understanding to your problem you want to get from the user some float numbers and then find the min and the max number of them. so in this case you have a lot of mistakes. the code should be:
package stackoverflow;
import java.util.Scanner;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
//number of inputs:
int numberOfInput = 4;
System.out.println("Enter " numberOfInput " values");
float numbers [] = new float [numberOfInput];
for (int i = 0; i < numberOfInput; i ) {
numbers[i] = input.nextFloat();
}
System.out.println("The big number is: " bigNumber(numbers));
System.out.println("The little Number is: " littleNumber(numbers));
}
public static float bigNumber(float [] numbers) {
float max1 = numbers[0];
for (int i = 0; i < numbers.length; i ) {
if(numbers[i] > max1) max1 = numbers[i];
}
return max1;
}
public static float littleNumber (float [] numbers) {
float min = numbers[0];
for (int i = 0; i < numbers.length; i ) {
if(numbers[i] < min) min = numbers[i];
}
return min;
}
}
sorry about my English