導航:首頁 > 編程語言 > ysinx在java編程

ysinx在java編程

發布時間:2022-08-30 17:24:35

java編程。。輸入三個整數x,y,z,請把這三個整數由小到大輸出,在線等,急,謝謝了

import java.util.Arrays;
import java.util.Scanner;

public class Three{
public static void main(String[] args) {

System.out.println("請輸入一個三位整數:");

Scanner sc = new Scanner(System.in);
int x =sc.nextInt();
int y =sc.nextInt();
int z =sc.nextInt();
int [] arr ={x,y,z};
//使用Arrays.sort()方法進行升序排序
Arrays.sort(arr);
for (int i : arr) {
System.out.print(i+" ");

}
}
}

㈡ 用java編寫簡單求導公式

求導的方法:
(1)求函數y=f(x)在x0處導數的步驟:
① 求函數的增量Δy=f(x0+Δx)-f(x0)
② 求平均變化率
③ 取極限,得導數。

(2)幾種常見函數的導數公式:
① C'=0(C為常數);
② (x^n)'=nx^(n-1) (n∈Q);
③ (sinx)'=cosx;
④ (cosx)'=-sinx;
⑤ (e^x)'=e^x;
⑥ (a^x)'=a^xIna (ln為自然對數)
⑦ loga(x)'=(1/x)loga(e)

(3)導數的四則運演算法則:
①(u±v)'=u'±v'
②(uv)'=u'v+uv'
③(u/v)'=(u'v-uv')/ v^2
④[u(v)]'=[u'(v)]*v' (u(v)為復合函數f[g(x)])

(4)復合函數的導數 復合函數對自變數的導數,等於已知函數對中間變數的導數,乘以中間變數對自變數的導數--稱為鏈式法則。

㈢ 關於java編程

Scannerscan=newScanner(System.in);
System.out.println("請輸入第一位實數");
intx=scan.nextInt();
System.out.println("請輸入運算符");
Stringop=scan.next();
System.out.println("請輸入第二位實數");
inty=scan.nextInt();
switch(op){
case"+":
System.out.println("結果為:"+(x+y));
break;
case"-":
System.out.println("結果為:"+(x-y));
break;
case"*":
System.out.println("結果為:"+(x*y));
break;
case"/":
System.out.println("結果為:"+(x/y));
break;
case"%":
System.out.println("結果為:"+(x%y));
break;
default:
break;
}

㈣ C語言編程求函數y=sinx在(0,1)區間的定積分

#include<stdio.h>
#include<math.h>

#define N 10000000

void main()
{
double sum=0;
int i;
for(i=0; i<N; i++)
{
sum += sin((double)(i)/N)/N;
}
printf("%lf\n%lf",sum,1-cos(1));
}

N後面的0有點多了,不過這個數剛好能精確到小數點後6位。
當然,這個程序的演算法實在是太垃圾了,效率非常的低下……

㈤ 用OpenGL編寫y=sinx的圖像

import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;

public class hanshu
{
public static void main(String[] args)
{
DrawFrame frame=new DrawFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}

}
class DrawFrame extends JFrame
{
public DrawFrame()
{
setTitle("DrawTest");
setSize(400,400);

// add panel to frame

DrawPanel panel = new DrawPanel();
add(panel);
}
}

class DrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;

int centerx=0;
int centery=0;
int minx=-150;
int maxx=150;
int miny=-150;
int maxy=150;

g2.translate(200,200);
g2.draw(new Line2D.Double(minx,centery,maxx,centery));
g2.draw(new Line2D.Double(maxx,centery,maxx-1,centery-1));
g2.draw(new Line2D.Double(maxx,centery,maxx-1,centery+1));
g2.drawString("X",151,0);
g2.draw(new Line2D.Double(centerx,miny,centerx,maxy));
g2.draw(new Line2D.Double(centerx,miny,centerx-1,miny+1));
g2.draw(new Line2D.Double(centerx,miny,centerx+1,miny+1));
g2.drawString("Y",-7,-145);
g2.drawString("Y=sinX",5,150);

int[] arrayy=new int[200];
int[] arrayx=new int[200];
arrayx[0]=-100;
for (int i=0;i<199;i++)
{
arrayx[i+1]=arrayx[0]+i;
}
for (int i=0;i<200;i++)
{
arrayy[i]=-Function(arrayx[i])/10;
}

g2.drawPolyline(arrayx,arrayy,200);

}
public static int Function(int x)
{
return X;
}
}

㈥ 怎麼用java編程,實現分數的加減乘除運算

1、打開eclipse,創建一個Java工程,在此工程里新建一個類;

2、在新建的類中,添加4個運算類;

3、在主方法中調用對應的方法即可完成分數的加減乘除運算了。

具體實現代碼如下:

public class Demo {

public static void main(String[] args) {

System.out.println(jia(1, 2));

System.out.println(jian(1, 2));

System.out.println(cheng(1, 2));

System.out.println(chu(1, 2));

}

//加法運算

private static float jia(float x,float y) {

return x + y;

}

//減法運算

private static float jian(float x,float y) {

return x - y;

}

//乘法運算

private static float cheng(float x,float y) {

return x * y;

}

//除法運算

private static float chu(float x,float y) {

return x / y;

}

}

㈦ 怎樣用C++編程繪制y=sinx 的一段曲線

與你擁有的軟體有關。繪曲線的關鍵是計算出曲線的x,y坐標,然後兩點連一線。
下面是用MS VC++ API 寫的繪曲線程序,畫時序曲線,可縮放,畫座標刻度..,現刪去了一些功能(未刪凈),供參考。
編譯時若有警告信息,可以或略。
設x0=0;dx=0.01;1000點。
#include <afxwin.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <Winuser.h>

#pragma comment (lib, "LIBCMT.LIB")

#define DEBUG 0

HWND hWndMain;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
void OnDisplayMessage(char *str);
void set_n_scale_y(int *ndiv, float ymin, float ymax, float *yu, float *yd, float *dy);
void set_n_scale_x(int *ndiv, float t0, float te, float *td, float *tu,float *draw_dt );
static float *yt,rx,ry,y_min,y_max,y_ran,y_shift;
static float draw_yu,draw_yd,draw_dy,draw_min,draw_max;
static float t0=0.0,dt=1.0,draw_tu,draw_td,draw_dt;
int flag_t0=0;
float bt_scale_1=1.0;
int draw_n=4,draw_nt=6;
char pname[40],namein[50],str[120],para2[10],para3[10],para4[10];;
char one_line[80];
int len,NN;
LPTSTR argv;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
MSG Msg;
int i;
//get cmd line
argv = GetCommandLine();
len = strlen(argv);
sprintf(one_line,"%s",argv);
i = sscanf(one_line,"%s %s %s %s %s",&pname[0],&namein[0],¶2[0],¶3[0],¶4[0]);
///===========
t0 = 0;
dt = 0.02;
draw_nt=6;
NN = 1000;
yt = (float *) malloc(NN * sizeof(float));
for (i=0;i<NN;i++) yt[i] = sin(t0+dt*i);

y_min=y_max=yt[0];
for (i=0;i<NN;i++){
if (yt[i] < y_min) y_min=yt[i];
if (yt[i] > y_max) y_max=yt[i];
};
y_ran = y_max - y_min;
ry = 150.0 / y_ran;
for (i=0;i<NN;i++) yt[i]= yt[i] - y_min;
y_shift = 180 ;
draw_max = y_max;
draw_min = y_min;
(void) set_n_scale_y(&draw_n, draw_min, draw_max, &draw_yu, &draw_yd, &draw_dy);

if (DEBUG == 1){
sprintf(str,"yd=%f yu=%f dy=%f y_max=%f y_min=%f n=%d", draw_yd,draw_yu,draw_dy,y_max,y_min,draw_n);
OnDisplayMessage(str);
};
(void) set_n_scale_x(&draw_nt, t0, t0+ dt*(NN), &draw_td, &draw_tu,&draw_dt);
if (DEBUG == 1){
sprintf(str,"td=%f tu=%f dt=%f n=%d", draw_td,draw_tu,draw_dt,draw_nt);
OnDisplayMessage(str);
};
rx = 900.0 / (draw_tu - draw_td);

if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;

ShowWindow(hWndMain,nCmdShow);
UpdateWindow(hWndMain);

while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static long nXChar,nYChar;
HDC hdc;
short x;
TEXTMETRIC tm;
PAINTSTRUCT ps;
COLORREF color;
HFONT font;
HPEN hP1; // pen
// CPoint aP,mousePos;
int i;

switch(message)
{
case WM_LBUTTONDOWN:
bt_scale_1 = bt_scale_1 + 0.05;
ry=ry*bt_scale_1;
y_shift = y_shift * bt_scale_1;
ShowWindow(hwnd, SW_HIDE);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
return 0;
case WM_RBUTTONDOWN:
ry=ry/bt_scale_1;
y_shift = y_shift / bt_scale_1;
ShowWindow(hwnd, SW_HIDE);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
return 0;
case WM_CREATE:
ScrollWindow(hwnd, 0, -800, NULL, NULL);

hdc=GetDC(hwnd);
GetTextMetrics(hdc,&tm);
nXChar=tm.tmAveCharWidth;
nYChar=tm.tmHeight;
ReleaseDC(hwnd,hdc);
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps); // begin paint
SetWindowExtEx(hdc,1200,800,NULL);
SetViewportExtEx(hdc,1200,800*bt_scale_1,NULL);
SetViewportOrgEx(hdc,100,150,NULL);

// draw grids
color=RGB(0,128,128);
hP1=CreatePen(PS_SOLID,0,color);
SelectObject(hdc,hP1);

MoveToEx( hdc,0, y_shift-(draw_yu-y_min)*ry, NULL );
LineTo(hdc,900,y_shift-(draw_yu-y_min)*ry);
LineTo(hdc,900,y_shift-(draw_yd-y_min)*ry);
LineTo(hdc,0,y_shift-(draw_yd-y_min)*ry);
LineTo(hdc,0,y_shift-(draw_yu-y_min)*ry);

for (i=0;i<=draw_n;i++)
{
MoveToEx( hdc, 0, y_shift-(draw_yd -y_min + i* draw_dy)*ry, NULL );
LineTo( hdc, 900, y_shift-(draw_yd -y_min + i * draw_dy)*ry );
}

for (i=1;i<draw_nt;i++) {
MoveToEx( hdc, 900 * i /draw_nt, y_shift-(draw_yd -y_min)*ry, NULL );
LineTo( hdc, 900 * i /draw_nt, y_shift-(draw_yu -y_min)*ry );
}
// draw curve
color=RGB(255,0,0);
hP1=CreatePen(PS_SOLID,0,color);
SelectObject(hdc,hP1);

MoveToEx( hdc, (t0-draw_td)* rx, y_shift-yt[0]*ry, NULL );
for (i=1;i<NN ;i++){
LineTo(hdc,(t0+i*dt-draw_td)*rx, y_shift-yt[i]*ry);
}

font=CreateFont(
24,10,0,0, FW_NORMAL,0,0,0, ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,NULL,"myfont"
);
SelectObject(hdc,font);
GetTextMetrics(hdc,&tm);
nYChar=tm.tmHeight;
color=RGB(0,0,0);
for (i=0;i<=draw_n;i++)
{
sprintf(one_line,"%.2f",draw_yd +i * draw_dy);
TextOut(hdc,-60,y_shift-(draw_yd-y_min + i* draw_dy)*ry-5,one_line,strlen(one_line));
}

for (i=0;i<=draw_nt;i++)
{
sprintf(one_line,"%.1f",draw_td +i * draw_dt);
TextOut(hdc,900 * i /draw_nt-30,y_shift-(draw_yd -y_min)*ry+20, one_line,strlen(one_line));
}

sprintf(one_line,"%s N=%d",namein,NN);
TextOut(hdc,20,y_shift-(draw_yu-y_min )*ry-40,one_line,strlen(one_line));

EndPaint(hwnd,&ps); // end paint
return 0L;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,message,wParam,lParam);

}

}

BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
// wndclass.hIcon=LoadIcon(NULL,"END");
wndclass.hIcon=LoadIcon(hInstance,"uni03.ico");
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName="Windows Fill";
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
return(RegisterClass(&wndclass));
}

BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
char str[100];
sprintf(str,"%s %s",pname,namein);
hWnd=CreateWindow(
"Windows Fill",
str,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)
return FALSE;
hWndMain=hWnd;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}

void OnDisplayMessage(char *str)
{
MessageBox(NULL,str,"msg",MB_OK | MB_ICONINFORMATION);
}

void set_n_scale_y(int *ndiv, float ymin, float ymax, float *yu, float *yd, float *dy)
{
int n ;
float yuu,ydd;
float yr;
if (*ndiv <= 0) {n = 2;} else n = *ndiv;
yr = ymax - ymin;
if ( yr >= 0.0001 && yr < 0.001) {
yuu = (float) ((int) (ymax * 10000.0)) / 10000.0f + 0.0001f;
ydd = (float) ((int) (ymin * 10000.0)) / 10000.0f - 0.0001f;
}
else if (yr >= 0.001 && yr < 0.01) {
yuu = (float) ((int) (ymax * 1000.0)) / 1000.0f + 0.001f;
ydd = (float) ((int) (ymin * 1000.0)) / 1000.0f - 0.001f;
}
else if ( yr >= 0.01 && yr < 0.1) {
yuu = (float) ((int) (ymax * 100.0)) / 100.0f + 0.01f;
ydd = (float) ((int) (ymin * 100.0)) / 100.0f - 0.01f;
}
else if ( yr >= 0.1 && yr < 1.0) {
yuu = (float) ((int) (ymax * 10.0)) / 10.0f + 0.1f;
ydd = (float) ((int) (ymin * 10.0)) / 10.0f - 0.1f;
}
else if ( yr >= 1.0 && yr < 10.0) {
yuu = (float) ((int) (ymax)) + 1.0f;
ydd = (float) ((int) (ymin)) - 1.0f;
}
else if ( yr >= 10.0 && yr < 100.0) {
yuu = (float) ((int) (ymax * 0.1)) / 0.1f + 10.0f;
ydd = (float) ((int) (ymin * 0.1)) / 0.1f - 10.0f;
}
else if ( yr >= 100.0 && yr < 1000.0) {
yuu = (float) ((int) (ymax * 0.01)) / 0.01f + 100.0f;
ydd = (float) ((int) (ymin * 0.01)) / 0.01f - 100.0f;
}
else if ( yr >= 1000.0 && yr < 10000.0) {
yuu = (float) ((int) (ymax * 0.001)) / 0.001f + 1000.0f;
ydd = (float) ((int) (ymin * 0.001)) / 0.001f - 1000.0f;
}
else if ( yr >= 10000.0 && yr < 100000.0) {
yuu = (float) ((int) (ymax * 0.0001)) / 0.0001f + 10000.0f;
ydd = (float) ((int) (ymin * 0.0001)) / 0.0001f - 10000.0f;
} else {
yuu = ymax; ydd = ymin;
};

if (yuu == ydd) {
yuu = ydd * 1.1f;
ydd = ydd * 0.9f;
};
*yu = yuu; *yd = ydd;
*dy = (yuu - ydd) / n;
if (*dy > 1.0) *dy = (float) ((int) *dy );
*ndiv = (yuu - ydd)/ (*dy) ;
}

void set_n_scale_x(int *ndiv, float t0, float te, float *td, float *tu,float *draw_dt )
{
int i;
int n ;
double tr,dt,d;

if (*ndiv <= 0) {n = 6;} else n = *ndiv;
tr = (double) (te - t0);
dt = tr / (double) n;

if (dt >= 1.0 ){d = (double) ((int) (dt + 0.9));}
else { d = dt;};
i = (int)( (double) t0 / d);
if (t0 < 0) i=i-1;
// if ( (float)(d * i) < t0) i = i + 1;
*td = (float) (d * i);
*ndiv = (int) ((te - *td) / d);
if ( *ndiv * d < (te - *td) ) *ndiv= *ndiv+1;
*tu = *td + *ndiv * d;
*draw_dt = (float) d;
}

㈧ java編程用泰勒級數計算arcsin

import java.util.*;
public class question2
{
//arcsin x = x + x^3/(2*3) + (1*3)x^5/(2*4*5) + 1*3*5(x^7)/(2*4*6*7)……+(2k+1)!!*x^(2k+1)/(2k!!*(2k+1))+……(|x|<1) !!表示雙階乘
public double arcsin(double x)
{
double y=x;
double m=1;
double n=2;
for(int i=1;i<100;i++)
{
y=y+m*Math.pow(x,2*i+1)/(n*(2*i+1));
m=m*(i+2);
n=n*(i+2);
}
return y;
}
public static void main (String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("請輸入一個正弦值x");
question2 q2=new question2();
double x=sc.nextDouble();
q2.arcsin(x);
if(x>1||x<-1)
{
System.out.println("請輸入正確的值");
}
System.out.println(" "+q2.arcsin(x));
}

}

㈨ java實現網頁動態成圖

將驗證碼圖片代碼捎加修改就ok

㈩ java 數據類型的轉換

public void paintComponent( Graphics g )

{
g.setColor( Color.red );
int[ ] x = new int[ 100 ];
int[ ] y = new int [ 100 ];
//你這邊i設成300不是數組溢出?
for( int i = 0; i <100; i++ )
{
//這邊i*10(10可以換成其他的數),這要是控制三角函數的寬度
x[ i ] = i*10;
/*這邊要注意的是如果你是20*(int)Math.sin(i),
*就會畫出一條直線,因為(int)(x)=0,在x<1時發生。
* +50是因為如果y為負值的時候,曲線的上部分是看不到的。
*/
y[ i ] = (int)(20*Math.sin(i))+50;
}
g.drawPolyline( x, y,100);
}
你去試一下,這個可以的;

閱讀全文

與ysinx在java編程相關的資料

熱點內容
工業壓縮機品牌 瀏覽:181
蘋果系統怎麼更改app的圖標 瀏覽:667
泰劇女同電影 瀏覽:435
人造變異女的電影 瀏覽:237
懷舊經典老錄像片 瀏覽:593
和利時功能塊怎麼加密 瀏覽:30
宣萱電影好看 瀏覽:568
韓國純真時代動態圖 瀏覽:100
關於男主有個能操控別人 瀏覽:303
怎麼測試doh加密 瀏覽:210
歐美 小說 圖片 瀏覽:908
西安程序員未來的發展趨勢 瀏覽:173
叫阿能的電影 瀏覽:261
客車購票小程序源碼 瀏覽:645
程序員用數據表白靈魂伴侶 瀏覽:485
spin命令行 瀏覽:376
百合txt下載 瀏覽:61
房貸結清合同是不是解壓了 瀏覽:109
小說資源鏈接 瀏覽:447
馬桶app怎麼開通 瀏覽:593