这里有什么问题? printf给出错误 [英] what is wrong here? The printf gives an error

查看:192
本文介绍了这里有什么问题? printf给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class AssignClass {

public static void main(String [] args){

int numArr [] = {82 ,60,72,50,3,39,47,20}; //整数数组
int smallTemp = numArr [0]; //将零元素分配为小数
int largeTemp = numArr [1]; //将第一个元素分配给大号

for(int i = 0; i< numArr.length; i ++)//迭代直到数组的结尾
{
if (largeTemp< numArr [i])//检查数组的值是否大于bigTemp
{
largeTemp = numArr [i];
}
if(smallTemp> numArr [i])//检查数组的值是否小于bigTemp
{
smallTemp = numArr [i];
}
}

System.out.printf(最大数字:%d\\\
,largeTemp); // print large number
System.out.printf(Smallest Number:%d\\\
,smallTemp); // print small number

}

}

printf下划线为红色,给出和错误?哪里不对?我使用Eclipse

解决方案

printf 看起来您的项目配置为使用Java 1.4。通过右键单击来更改项目的配置,然后转到属性:




  • 选择Java Build Path选项,确保您为您的项目使用适当的Java JDK版本。

  • 选择Java编译器选项,确保使用Java 1.5或更高版本。



如果您碰巧在Java 8中创建项目,请确保使用Eclipse Luna或Eclipse Kepler与Java 8支持的插件。 IMO建议您使用Eclipse Luna。免责声明:我不是Eclipse或任何其他Eclipse基础技术的贡献者,只是这个工具的快乐用户。


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

    }

}

The printf is underlined in red and gives and error? What is wrong? I used Eclipse

解决方案

printf is available since Java 5., so looks like your project is configured to use Java 1.4. Change the configuration of your project by right clicking on it, then go to Properties:

  • Select Java Build Path option and make sure you're using the proper Java JDK version for your project.
  • Select Java Compiler option and make sure you're using Java 1.5 or superior.

If you happen to create a project in Java 8, make sure you're using Eclipse Luna or Eclipse Kepler with the plugin for Java 8 support. IMO I recommend you to use Eclipse Luna. DISCLAIMER: I'm not contributor of Eclipse or any other Eclipse-base technology, just a happy user of this tool.

这篇关于这里有什么问题? printf给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆