?? ex030202.java
字號(hào):
import java.io.*;
public class Ex030202{
static long method1(int x){
int fx=0;
if (x<0)
fx=2*x-1;
else if (x<3 && x>=0)
fx=3*x+5;
else if (x<5 && x>=3)
fx=x+1;
else if (x<10 && x>=5)
fx=5*x-3;
else if (x>=10)
fx=7*x+2;
return fx;
}
static long method2(int x){
int fx=0;
switch(x) {
case 0:
case 1:
case 2:
fx=3*x+5;
break;
case 3:
case 4:
fx=x+1;
break;
case 5:
case 6:
case 7:
case 8:
case 9:
fx=5*x-3;
break;
default:
if (x>=10)
fx=7*x+2;
else
fx=2*x-1;
}
return fx;
}
public static void main(String[] args){
int x=0;
Reader ir = new InputStreamReader(System.in);
BufferedReader r = new BufferedReader(ir);
String sc="";
System.out.print(" x = ");
try{
sc = r.readLine();
}catch (IOException e){}
try{
x=Integer.parseInt(sc);
}catch (NumberFormatException e){
System.out.println("輸入的數(shù)據(jù)不是整數(shù)");
System.exit(1);
}
System.out.println("f(x) = "+method1(x));
System.out.println("f(x) = "+method2(x));
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -