JAVA.7

Preparation of a simple program 1, claim 5 length arrays, static assignment 10,20,30,40,50, the value of the output array console. SSA Package; 


public class lianxi { 
	public static void main (String [] args) { 
		int [] = ARR new new int [] {10,20,30,40,50}; 
		for (int I = 0; I <ARR. length; I ++) { 
		of System.out.print (ARR [I] + ""); 
				
			
		} 
		
			
			

		
	       
      

	        } 
	}

  

2. Write a simple procedure that requires the array length is 5, 10, 20 dynamically assigned, the output value of the array in the console. 
SSA Package; 
Import java.util.Scanner; 
public class lianxi { 
	public static void main (String [] args) { 
		int ASS [] = new new int [. 5]; 
		Scanner Scanner new new SC = (the System.in); 
		for (int 0 = I; I <ass.length; I ++) { 
			System.out.println ( "enter a number"); 
			ASS [I] = sc.nextInt (); 
		} 
		System.out.println ( "assigned end ~ ~~~~~~~~~~~~~~~~~~~ "); 


				
			
		}

  

3. Write a simple procedure, the definition of an integer array, which elements are {23,45,22,33,56}, and the required array elements, the average value; 
Package SSA; 
public class lianxi { 
	public static void main (String [] args) { 
		int ASS [] = {23,45,22,33,56}; 
		int SUM = 0; 
		for (int I = 0; I <ass.length; I ++) { 
			SUM ASS = + [I]; 
		} 
		System.out.println (SUM); 

				
			
		} 
		
			


	        }
	

  

4. In a number of the largest array of eight integers (18,25,7,36,13,2,89,63) and find the index. 
SSA Package; 
public class lianxi { 
	public static void main (String [] args) { 
		int [] = A new new int [] {} 18,25,7,36,13,2,89,63; 
		
		
		int X = 0; 
		A max = int [0]; 
		for (int I =. 1; I <-a.length. 1; I ++) 
		{ 
			IF (A [I]> max) 
			{ 
				max = A [I]; 
				X = I; 
			} 
		} 
		the System .out.println ( "maximum number" + max + "; subscript" + X); 
	} 

				
			
		}
		

  

Guess you like

Origin www.cnblogs.com/Libreation/p/12665296.html