第1个回答 2013-10-11
import java.util.Scanner;
public class count()
{
int x,y;
public void account()
{
System.out.println("请输入X的值");
Scanner scan=new Scanner(System.in);
x=scan.nextInt();
if(x<0)
{
y=-1+2*x;
}
else if(x=0)
{
y=-1;
}
else if(x>0)
{
y=-1+3*x;
}
}
public static void main(String[] args)
{
count a= new count();
a.account();
}
}
第2个回答 2013-10-11
import java.util.Scanner;
//有一函数,x<0时,y=-1+2x;x=0时,y=-1;
//x>0时,y=-1+3x。编写一个java应用程序,从键盘输入一个x值,程序输出y的值。
public class acm {
public static void main(String args[]){
Scanner Sca=new Scanner(System.in);
System.out.println("从键盘输入一个x值");
int x;
x=Sca.nextInt();
int y;
if(x>0){
y=-1+3*x;
}
else if(x==0){
y=-1;
}
else{
y=-1+2*x;
}
System.out.println(y);
}
}本回答被网友采纳