import java.util.Scanner; Public class lab2_2 { Public static void main (String args []) { System. The out. Println (" Sum="+ sumArray ()); System. The out. Println (" business="+ aveArray ()); } Public static int [] fillArray () { Scanner sc=new Scanner(System.in); String STR=sc. Next (); Int length=Integer. ParseInt (STR); An int array []=new int (length), for(int i=0; i{ String str2=sc. Next (); Int num=Integer. ParseInt (str2); Array [I]=num; } Return array; } Public static int sumArray () { Int array1 []=fillArray (); Int sum=0; for(int i=0; i{ Sum=sum + array1 [I]; } Return the sum. } Public static int aveArray () { Int array1 []=fillArray (); Int sum=sumArray (); Int length=array1. Length; Int ave=sum/length; Return ave. }
}
Why the execution of a program when the main method of the second output does not show
CodePudding user response:
Sc. Next left her a newline after read the content in the input buffer, so if you don't empty the input buffer, next time will read in an empty string To sc. NextLine