一加到四的java代码 一加到四的java代码是什么

(java语言)while 语句从一加到一百怎么写

int i = 1, sum = 0;

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:申请域名雅安服务器托管、营销软件、网站建设、西岗网站维护、网站推广。

while (i = 100) {

sum += i ++;

}

java递归算法

1.汉诺塔问题

import javax.swing.JOptionPane;

public class Hanoi {

private static final String DISK_B = "diskB";

private static final String DISK_C = "diskC";

private static final String DISK_A = "diskA";

static String from=DISK_A;

static String to=DISK_C;

static String mid=DISK_B;

public static void main(String[] args) {

String input=JOptionPane.showInputDialog("please input the number of the disks you want me move.");

int num=Integer.parseInt(input);

move(num,from,mid,to);

}

private static void move(int num, String from2, String mid2, String to2) {

if(num==1){

System.out.println("move disk 1 from "+from2+" to "+to2);

}

else {

move(num-1,from2,to2,mid2);

System.out.println("move disk "+num+" from "+from2+" to "+to2);

move(num-1,mid2,from2,to2);

}

}

}

2. 这是一个排列的例子,它所做的工作是将输入的一个字符串中的所有元素进行排序并输出,例如:你给出的参数是"abc" 则程序会输出:

abc

acb

bac

bca

cab

cba

(1)算法的出口在于:low=high也就是现在给出的排列元素只有一个时。

(2)算法的逼近过程:先确定排列的第一位元素,也就是循环中i所代表的元素,

然后low+1开始减少排列元素,如此下去,直到low=high

public static void permute(String str) {

char[] strArray = str.toCharArray();

permute(strArray, 0, strArray.length - 1);

}

public static void permute(char[] list, int low, int high) {

int i;

if (low == high) {

String cout = "";

for (i = 0; i = high; i++)

cout += list[i];

System.out.println(cout);

} else {

for (i = low; i = high; i++) {

char temp = list[low];

list[low] = list[i];

list[i] = temp;

permute(list, low + 1, high);

temp = list[low];

list[low] = list[i];

list[i] = temp;

}

}

}

3。这是一个组合的例子,与上述的例子相似,只是它所做的工作是,输出所给字符串中制定数目的元素的组合种类

(1)程序出口在于n=1,此时只要输出目标数组的所有元素即可

(2)逼近过程,当n1 的时候,我们先取第一个元素放入目标数组中,然后n-1,如此下去,最后出来。

import javax.swing.JOptionPane;

public class Combination {

/**

* @param args

*/

public static void main(String[] args) {

String input = JOptionPane.showInputDialog("please input your String: ");

String numString = JOptionPane.showInputDialog("please input the number of your Combination: ");

int num = Integer.parseInt(numString);

Combine(input, num);

}

private static void Combine(String input, int num) {

char[] a = input.toCharArray();

String b = "";

Combine(a, num, b, 0, a.length);

}

private static void Combine(char[] a, int num, String b, int low, int high) {

if (num == 0) {

System.out.println(b);

} else {

for (int i = low; i a.length; i++) {

b += a[i];

Combine(a, num - 1, b, i+1, a.length);

b=b.substring(0, b.length()-1);

}

}

}

}

从一加到五十求和?用Dreamweaver 8代码写出来

写了一个可以输入任意数字求和的asp代码。

form id="form1" name="form1" method="post" action=""

输入一个整数:

input name="n" type="text" id="n" size="5" /

input type="submit" name="Submit" value="提交" /

/form

p计算:1+2+3+……+N的值/p

pbr /

你输入的值为:%=request.Form("n")%/p

%

dim n,m

n=request.Form("n")

m=(1+n)*n/2

%

p1+2+3+……+%=request.Form("n")%=%=m%/p

JAVA 如何编写1+2+3+......X=100 求X

这道题应该这么写,但是这个程序本来就没有解,所以输出的是脏数据,这可能要用到异常处理,我就不想多写了

你自己慢慢研究吧

public class Countx {

public static void main(String[] args){

int sum =0;

int x = 1;

while(sum!=100){

sum+=x;

x++;

}

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

}

}


网页题目:一加到四的java代码 一加到四的java代码是什么
分享路径:http://ybzwz.com/article/ddcepjc.html