19-7 / 3 job: Get the lowest price mobile phone

| - operational requirements

| - problem-solving ideas

These prices are the minimum requirements

 

| - Content Code

java.util.Scanner Import; 

/ **
* @auther Zhou Xiaolong ::
* @Description: enter a price for the minimum
* @program: Xunhuan
* @Create: 2019-07-03 11:47
* /
public class GetMin {
static SC = new new Scanner Scanner (the System.in);
public static void main (String [] args) {
// required to enter the price of the four stores;
System.out.println ( "Please enter the store prices 4:");
// declare an integer array, the length. 4
int [] =. price new new int [. 4];
// for loop receiving an input
for (int I = 0; I <price.length; I ++) {
of System.out.print ( "on" + (i + 1) + " store price:");
. price [I] = sc.nextInt ();
}
// define a variable, for aligning
int min = price [0];
for (int I = 0; I <price.length; I ++) {
IF (. price [I] <min) {
min. price = [I];
}
}
System.out.println ( "four stores, the lowest price is: "+ min);

}
}



| - operating results



| - error log:
Error Description: Incorrect minimum output
error reason: when the assignment, the assignment should be marked when the number corresponding to min, instead of the subscript assigned to the variable number corresponding to the stored minimum value
to correct manner : below, into the min = i min = price [i]

Correction ago


After correction

 



 

Guess you like

Origin www.cnblogs.com/twuxian/p/11125664.html