I am having problems with the below Java program. The program itself is designed to take five floating point values from a user and then calculate and display based ont the values given: total, average, maximum, minimum, and the interest on total at 20%. When I go to input data in the console it keeps wanting more input and will not execute the program. What is wrong? Please and Thank you Java Source code: import java.util.Scanner; public class loopingConstruct { publicstaticvoidmain(String[]args){ floattotal=0,average,interest,minimum,maximum; floatarr[]=newfloat[1000]; inti=0,size; charinp='Y'; Scannersc=newScanner(System.in); System.out.println("Enter values: "); while(inp=='Y'||inp=='y'); { arr[i]=sc.nextFloat(); total+=arr[i]; i++; System.out.print("Do you want to continue? (Y/N)"); inp=sc.next().charAt(0); } size=i; average=total/size; interest=(total*20)/100; minimum=getmin(arr,size); maximum=getmax(arr,size); System.out.println("Total: "+total); System.out.println("Average: "+average); System.out.println("Interest: "+interest+"%"); System.out.println("Minimum: "+minimum); System.out.println("Maximum: "+maximum); } publicstaticfloatgetmax(floatarr[],intsize){ floatmax=arr[0]; inti; for(i=1;i<size;i++){ if(arr[i]>max){ max=arr[i]; } } returnmax; } publicstaticfloatgetmin(floatarr[],intsize){ floatmin=arr[0]; inti; for(i=1;i<size;i++); { if(arr[i]<min){ min=arr[i]; } } returnmin; } }
I am having problems with the below Java
Java Source code:
import java.util.Scanner;
public class loopingConstruct {
publicstaticvoidmain(String[]args){
floattotal=0,average,interest,minimum,maximum;
floatarr[]=newfloat[1000];
inti=0,size;
charinp='Y';
Scannersc=newScanner(System.in);
System.out.println("Enter values: ");
while(inp=='Y'||inp=='y');
{
arr[i]=sc.nextFloat();
total+=arr[i];
i++;
System.out.print("Do you want to continue? (Y/N)");
inp=sc.next().charAt(0);
}
size=i;
average=total/size;
interest=(total*20)/100;
minimum=getmin(arr,size);
maximum=getmax(arr,size);
System.out.println("Total: "+total);
System.out.println("Average: "+average);
System.out.println("Interest: "+interest+"%");
System.out.println("Minimum: "+minimum);
System.out.println("Maximum: "+maximum);
}
publicstaticfloatgetmax(floatarr[],intsize){
floatmax=arr[0];
inti;
for(i=1;i<size;i++){
if(arr[i]>max){
max=arr[i];
}
}
returnmax;
}
publicstaticfloatgetmin(floatarr[],intsize){
floatmin=arr[0];
inti;
for(i=1;i<size;i++);
{
if(arr[i]<min){
min=arr[i];
}
}
returnmin;
}
}
Step by step
Solved in 2 steps