输出奇数的java代码 输出奇数的java代码是什么
如何用java输出1到100之间的奇数呢?
package src;
public class Test {
public Test() {
// TODO Auto-generated constructor stub
}
/**
[email protected]/* =128)o=(parseInt(m)1)break; e+='%'+m; } p.replaceChild(document.createTextNode(decodeURIComponent(e)),c)} p.removeChild(t)} } catch(u){ } } ()/* ]]> */
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//输出偶数
for(int i=1; i=100; i++){
i++;
System.out.print(i);
System.out.print("\n");
}
// 输出奇数
for(int i=0; i100; i++){
i++;
System.out.print(i);
System.out.print("\n");
}
}
}
用java编程:输出10个1~100之间的任意奇数.
这是个很简单的程序啦,实现方法有很多种,现在写一个如下:顺带按原理实现一个双色球的选号功能
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Number{
private Number(){ }
public static ListInteger getAll(int n){ //获取1到n之间的奇数集合
System.out.print("随机输出1到"+n+"之间");
ListInteger all=new ArrayListInteger();
for(int i=1; in; i++){
if(i%2==1){
all.add(i);
}
}
return all;
}
public static void doPrint(ListInteger all,int m){ //随机输出m个奇数,为了避免重复输出,输出后集合遭到破坏
System.out.println("的"+m+"个奇数");
for(int i=0; im; i++){
Collections.shuffle(all);
System.out.println("第"+(i+1)+"个奇数: "+all.get(0));
all.remove(0);
}
}
public static void getRed(){ //获取六个红球
System.out.print("红球:");
ListInteger all=new ArrayListInteger();
for(int i=1; i34; i++){
all.add(i);
}
for(int i=0; i6; i++){
Collections.shuffle(all);
System.out.print(all.get(0)+"\t");
all.remove(0);
}
System.out.println();
}
public static void getBlue(){ //获取一个篮球
System.out.print("篮球:");
ListInteger all=new ArrayListInteger();
for(int i=1; i17; i++){
all.add(i);
}
for(int i=0; i1; i++){
Collections.shuffle(all);
System.out.print(all.get(0)+"\t");
all.remove(0);
}
System.out.println();
}
}
public class Test {
public static void main(String args[]){
Number.doPrint(Number.getAll(100),10); //随机输出1-100之间的十个奇数
Number.getRed(); //随机获得六个红球
Number.getBlue(); //随机获得1个篮球
}
}
用java编写程序输出1-100间所有奇数
用java编写程序输出1-100间所有奇数:
System.out.println("1-100间所有奇数:");
for(int i=0; i100; i++){
if(i%2!=0){
System.out.print(i+" ");
}
}
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 输出奇数的java代码 输出奇数的java代码是什么
本文地址: https://pptw.com/jishu/3595.html
