public class AssignClass { public static void main(String[] args) { int numArr[] = {82,60,72,50,3,39,47,20}; //integer array int smallTemp = numArr[0]; //assigning zeroth element as small number int largeTemp = numArr[1]; //assigning first element as large number for(int i=0; i<numArr.length;i++) //iterating till the end of the array { if(largeTemp<numArr[i]) //check if i'th value of array is large than largeTemp { largeTemp=numArr[i]; } if(smallTemp>numArr[i]) //check if i'th value of array is small than largeTemp { smallTemp=numArr[i]; } } System.out.printf("Largest Number: %d\n", largeTemp); //print large number System.out.printf("Smallest Number: %d\n", smallTemp); //print small number } }
printf下划线为红色并给出错误信息?怎么了?我用过Eclipse
printf从Java 5开始可用。因此,看起来您的项目已配置为使用Java 1.4。右键单击更改项目的配置,然后转到“属性”:
printf
如果碰巧要用Java 8创建项目,请确保您使用的是带有Java 8支持插件的Eclipse Luna或Eclipse Kepler。IMO我建议您使用Eclipse Luna。免责声明:我不是Eclipse或其他任何基于Eclipse的技术的贡献者,只是对该工具的满意的用户。