import java.util.Random;
class A extends Thread
{
\tint i=1;
\tRandom r=new Random();
\tpublic void run()
\t{
\t\twhile(i<100)
\t\t{
\t\t\tSystem.out.println("奇数:"+i);
\t\t\ti+=2;
\t\t\ttry
\t\t\t{
\t\t\t\tThread.sleep(r.nextInt(500));
\t\t\t}
\t\t\tcatch(InterruptedException e)
\t\t\t{
\t\t\t\te.printStackTrace();
\t\t\t};
\t\t}
\t}
}
class B implements Runnable
{
\tint i=2;
\tRandom r=new Random();
\tpublic void run()
\t{
\t\twhile(i<=100)
\t\t{
\t\t\tSystem.out.println("偶数:"+i);
\t\t\ti+=2;
\t\t\ttry
\t\t\t{
\t\t\t\tThread.sleep(r.nextInt(500));
\t\t\t}
\t\t\tcatch(InterruptedException e)
\t\t\t{
\t\t\t\te.printStackTrace();
\t\t\t}
\t\t}
\t}
}
public class TestThread
{
\tpublic static void main(String[] args)
\t{
\t\tnew A().start();
\t\tnew Thread(new B()).start();
\t}
}
第二个线程用循环打印从a到b之间的字符。
这句是a到z的字符吧。
public class A {
class Thread1 implements Runnable{//内部类,输出数字
public void run(){
System.out.println("1~100的奇数为:");
for(int i=1;i<=100;i++){
if(i%2==1){
System.out.println(i);
}
}
}
}
class Thread2 implements Runnable{//内部类,输出字母
public void run(){
System.out.println("a~z之间的字母为:");
for(char c='a'; c<='z'; c++){
System.out.println(c);
}
}
}
public static void main(String[] args){
A a = new A();
Thread t1 = new Thread(a.new Thread1());//实例化线程
Thread t2 = new Thread(a.new Thread2());
t1.start();//启动线程
t2.start();
}
}
public class Test{
public static void main(String [] args){
for(int i=0;i<100;i++){
if(i%2==0){
System.out.println("偶数:"+i);
}else{
System.out.println("奇数:"+i);
}
}
}
}
//////////////////////////////////////////////////
// requestOddNumber o=2n-1
// requestEvenNumber e=2n
// o,e∈N, o,e∈(1,100)
// ∑o=3+5+...+99
// ∑e=2+4+...+98
//////////////////////////////////////////////////
package math;
public class oen {
public static int sumOn(int m,int n){
if(m>n){m^=n;n^=m;m^=n;}
m+=1+(m&1);int sum=0;
while(m
return sum;
}
public static int sumEn(int m,int n){
if(m>n){m^=n;n^=m;m^=n;}
m+=1+((m+1)&1);int sum=0;
while(m
return sum;
}
public static void main(String[] args){
int m=1;int n=100;
System.out.println(m+"到"+n+"间奇数的和为:"+sumOn(m,n));
System.out.println(m+"到"+n+"间偶数的和为:"+sumEn(m,n));
}
}
我用的手机。写代码太慢,给你个思路吧
1.用Random生成数
Random random= new Random(101)
2.用do while循环,如果生成0从新循环!生名个计数器count=1 count++ 如果count=20 让循环break掉!
3.生名两个Interge数组!循环一下你那20个随机数,如果对2取余衡等于0,放入偶数数组,else的话放奇数!如果要代码。滴滴一下,明天给你发
#Java编程# 编写一个应用程序创建两个线程,一个线程打印输出1~100之间所有的奇数,另外一 -
: import java.util.Random; class A extends Thread { int i=1; Random r=new Random(); public void run() { while(i<100) { System.out.println("奇数:"+i); i+=2; try { Thread.sleep(r.nextInt(500)); } catch(InterruptedException e) { e.printStackTrace(); }; ...
Java编写一程序
: package myrandom;import java.util.*;public class SuiJi{public static void main(String[] args){SuiJi s=new SuiJi();s.t();} public void t(){ int sum=0,n=0,jishu=0,oushu=0;Random r=new Random();for(int i=0;i<200;i++){ int k=(Math.random()*1000+100); ...
用Java编写一程序 -
: 完整程序见下,记得采用啊:import java.util.*; class MinusException extends ArithmeticException { public MinusException() { } public MinusException(String str) { super(str); } } class OverException extends ArithmeticException { public ...
编写一个JAVA程序 -
: import java.util.Date; class Telephone{ private String brand; private String phoneNum; private int seconds; private double rate; public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public String ...
java 编程,代码一怎么写
: 代码一:public double average(double x[]){ double sum=0,average=0; for(int i=0;i
编写一个JAVA程序
: import java.util.*; public class ManyClasses {public static void main(String args[]){int st[]=new int[3];for(int i=0;i<3;i++){st[i]=Integer.parseInt( args[i]); //转换}Arrays.sort(st); //排序 System.out.println("最大值="+st[2]);System.out....
用JAVA编写一个程序
: class FineMinNum { public static void main(String[] args) { Scanner input=new Scanner(System.in); int min=0; string choice=""; do {int[] array=new int[6];for(int i=0;i
编写一个的JAVA程序,求完整代码 -
: public class Demo3 { public static void main(String[] args) { byte a =1; short b=1; int c = 1; long d = 1l; float e=1f; double f =1; char g ='1'; boolean h = true; System.out.println("byte a ="+a); System.out.println("short b="+b); System.out.println("int...
java编程,写一个程序 -
: 写了段代码,这里销售量做了整数限制,你参考下,是否有问题 最终算得结果,销售量为:210834,此时收入30000.08 package com.huangcy.test;/** * @author Huangcy * */ public class CalSalary { public static final double BASIC_COMM= 5000...
使用java编写一个程序
: public class CalcText{ public static void main(String[] args) { System.out.println("百位为2,能被3整除的数为:"); for(int i=200;i<=9999;i++) { if(i/100%10==2&&i%3==0) { System.out.println(i); } } }}