资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

分段函数的java的代码 分段函数java程序

用Java方法输出如下分段段函数,一定要用方法输出,求大神

x=6时,y=x-12

专注于为中小企业提供成都网站设计、成都做网站、外贸网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业定州免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了千余家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

x大于等于6时,y=3x-1

你这题目认真的?x=6,Y到底怎么取值?

你问题是不是x6 , y=x-12???

用java语言编程 设y=f(x)是一个分段函数,表达式如下

public class Demo{

public static void calc(double x){

double y= 0;

if(x=0){

y= x*x+1;

}else if(x0 x=10){

y= 2*x+10;

}else{

y= 7*x-15;

}

System.out.println("x="+x+",结果y="+y);

}

public static void main(String[] args){

Demo.calc(-5);

Demo.calc(6);

Demo.calc(30);

}

}

求大神指导用Java编程求分段函数(要求用if…else语句实现)

运行结果:

代码如下:

import java.util.Scanner;

public class App65 {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("请输入x值:");

int x = scanner.nextInt();

int y = 0;

if (x  0) {

y = x * x;

} else if (x = 0  x  10) {

y = 2 * x - 1;

} else if (x = 10) {

y = 3 * x - 11;

}

System.out.println("y=" + y);

}

}

急求 JAVA编程题——分段函数

大哥您的这个的题目明显是叫您用您的最好的美感去做一个界面,至于函数的实现您直接IF语句就OK了 ,您这个题目的目的在于界面,下次把要做的界面发过来。

我跟你来一个特脑残的看见就想砍人的界面。下面代码!

代码:

package com.lxp.p2015929;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JTextArea;

public class SectionFunc extends JFrame {

private static final long serialVersionUID = System.currentTimeMillis();

private JTextArea textarea1 = null;

private JTextArea textarea = null;

public SectionFunc() {

this.layoutFrame();

}

private void layoutFrame() {

this.setTitle("分段函数计算");

this.setSize(400, 250);

this.setLayout(null);

JLabel messagelabel1 = new JLabel("X值");

messagelabel1.setSize(120, 30);

messagelabel1.setLocation(20, 20);

this.add(messagelabel1);

JLabel messagelabel2 = new JLabel("Y值");

messagelabel2.setSize(120, 30);

messagelabel2.setLocation(250, 20);

this.add(messagelabel2);

textarea = new JTextArea();

textarea.setSize(100, 120);

textarea.setLocation(20, 60);

this.add(textarea);

textarea1 = new JTextArea();

textarea1.setSize(100, 120);

textarea1.setLocation(250, 60);

this.add(textarea1);

JButton button = new JButton("计算");

button.setSize(100, 30);

button.setLocation(130, 120);

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

SectionFunc.this.textarea1.setText(SectionFunc

.XToY(SectionFunc.this.textarea.getText()));

}

});

this.add(button);

this.setLocationRelativeTo(null);

this.setDefaultCloseOperation(EXIT_ON_CLOSE);

}

private static String XToY(String x) {

long tenx = Long.parseLong(x);

long teny = 0;

if (tenx 0) {

teny = 3 * tenx - 1;

} else if (tenx == 0) {

teny = -1;

} else {

teny = 2 * tenx - 1;

}

return String.valueOf(teny);

}

public static void main(String[] args) {

SectionFunc sectionfunc = new SectionFunc();

sectionfunc.setVisible(true);

}

}


当前题目:分段函数的java的代码 分段函数java程序
分享URL:http://cdkjz.cn/article/ddidioo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220