导航:首页 > 编程语言 > 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编程相关的资料

热点内容
吃鸡手机国际服服务器超时怎么办 浏览:68
努比亚Z5无命令 浏览:640
展示网站云服务器 浏览:870
代码混淆器php 浏览:365
贝恩pdf 浏览:207
丙烯pdf 浏览:366
云服务器华硕 浏览:711
sublime3运行python 浏览:188
怎么把安卓视频传到苹果上面 浏览:81
手机拍鬼片用什么app 浏览:640
爬山虎app是干什么用的 浏览:505
有哪些写给程序员的歌 浏览:49
成都市命令 浏览:993
建立系列文件夹 浏览:983
苹果开机白屏带文件夹问号 浏览:733
体验服为什么服务器会关闭 浏览:41
酒店命令 浏览:750
中走丝线切割编程视频 浏览:80
衣服压缩袋手泵原理 浏览:714
通达信编程书籍 浏览:981