x=6時(shí),y=x-12
專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站、外貿(mào)網(wǎng)站建設(shè)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)定州免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了千余家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
x大于等于6時(shí),y=3x-1
你這題目認(rèn)真的?x=6,Y到底怎么取值?
你問題是不是x6 , y=x-12???
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+",結(jié)果y="+y);
}
public static void main(String[] args){
Demo.calc(-5);
Demo.calc(6);
Demo.calc(30);
}
}
運(yùn)行結(jié)果:
代碼如下:
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);
}
}
大哥您的這個(gè)的題目明顯是叫您用您的最好的美感去做一個(gè)界面,至于函數(shù)的實(shí)現(xiàn)您直接IF語句就OK了 ,您這個(gè)題目的目的在于界面,下次把要做的界面發(fā)過來。
我跟你來一個(gè)特腦殘的看見就想砍人的界面。下面代碼!
代碼:
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("分段函數(shù)計(jì)算");
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("計(jì)算");
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);
}
}