⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chapter8n2.java

📁 JAVA源代码程序aashjkjhkjhkjhjkhkj
💻 JAVA
字号:
/** * * Extended program to test the "Temperature" class * */public class Chapter8n2    {    public static void main(String [] args)	{	String flag, strCel;	Double myDouble = new Double(0.0);	double temp;	boolean valid = true;	Temperature temperature = new Temperature();	char flagChar;	// have we got two arguments?	if (args.length != 2)	    {	    System.out.println("incorrect number of arguments : 2 expected"); 	    System.exit(1);	    }	// does the first argument look like a flag?	flag = args[0];	if (flag.charAt(0) != '-')	    {	    System.out.println("first argument not a flag");	    System.exit(1);	    }	// ok it's a flag but is it valid?	flagChar = flag.charAt(1);	switch (flagChar)	    {	    case 'f' :	    case 'c' :		break;	    default :		System.out.println("unknown flag [" + flagChar + "] used"); 		System.exit(1);	    }	strCel = args[1];	try {	    myDouble = Double.valueOf(strCel);	    }	catch (NumberFormatException e)	    {	    System.out.println("parameter provided [" + 		strCel + "] not in double format"); 	    valid = false;	    }	if (valid)	    {	    temp = myDouble.doubleValue();	    switch (flagChar)		{		case 'f' :		    temperature.setFahr(temp); 		    break;		case 'c' : 		    temperature.setCelsius(temp);		}	    System.out.println(temperature); 	    }	}// end of main method    } // end of class Chapter8n2

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -