java编程实例大全,java编程运算几个具体实例

1,java编程运算几个具体实例三个案例1、编写一个方法fun_01(),判断一个整数是否包含数字7.public class Test01public static void main(String[] args) Scanner sc =new Scanner(System.in);System.out.println("请输入数值: ");int num = sc.nextInt();System.out.println(func2( num));}public static boolean fun_01(int num)int n;boolean flag=false;while(num!=0)n=num%10;if(n==7)flag=true;break;}num /= 10;}return flag;}}2.metod2(),对输入的任意字符串“1,4,7,13,5,17,9”转换为数组元素是整数元素,需要保存在整形数组中且实现排序输出“1 4 5 7 9 13 17”public class Demo public static void main(String[] args) // String str =("1,4,7,13,5,17,9");Scanner sc = new Scanner(System.in);System.out.println("请输入数字字符串,并用逗号隔开");String str = sc.next();metod2(str);}public static void metod2(String str)String array[] = str.split(",");int p[]=new int[array.length];for(int i=0;i<array.length;i++)p[i]=Integer.parseInt(array[i]);}//Arrays.sort(p);for(int i=0;i<p.length-1;i++)for(int j=0;j<p.length-1-i;j++)if(p[j]>p[j+1])int temp =p[j];p[j]=p[j+1];p[j+1]=temp;}}}for(int i=0;i<p.length;i++)System.out.print(p[i]+" ");}}}3,编写一个方法,传入数值 , 打印出金字塔public static void print(int num)for(int i=0;i<num;i++)for(int k=0;k<num-i-1;k++)System.out.print(" ");}for(int j=0;j<2*i+1;j++)System.out.print("*");}System.out.println();}}
2,java经典编程案例有哪些java编程的记事本:import java.util.*;public class JieChengExamplepublic static void main(String args[])Scanner input=new Scanner(System.in);int n,sum;Jiecheng jie=new Jiecheng();System.out.print("输入n的值:");//输入有几个阶乘相加n=input.nextInt();sum=0;for(int i=1;i<=n;i++)sum=sum+jie.jiecheng(i);//这是n个阶乘相加}System.out.println("1!+2!+3!+....+n!的和是:"+sum);}}class Jiechengpublic int jiecheng(int temp)//算阶乘的方法int sum=1;for(int i=1;i<=temp;i++)sum=sum*i; //计算阶乘}return sum;//将一个阶乘返回}}2.java赛马游戏:import java.util.Random;public class Test public static void main(String[] args) Competition c = new Competition();Thread T = new Thread(c);T.start();}}class Competition implements Runnableint red = 0;int green = 0;int Speed [] = new int [2];Competition()}public void run()Random r = new Random();for(int a= 0;a<500;a++)for(int j = 0;j<2;j++)Speed[j] = r.nextInt(2);red = red + Speed[j];Speed[j] = r.nextInt(2);green = green + Speed[j];}System.out.println("red的速度为"+red);System.out.println("green的速度为"+green);while(red >=500 || green>=500)if(red >=500)System.out.println("red先抵达终点线");}if(green >= 500)System.out.println("green先抵达终点线");}if(green ==500 && red ==500 )System.out.println("两个同时到达");}return;}}/*if(red >green)System.out.println("Redwin"+red);}if(red<green)S...import java.util.Random;public class Test public static void main(String[] args) Competition c = new Competition();Thread T = new Thread(c);T.start();}}class Competition implements Runnableint red = 0;int green = 0;int Speed [] = new int [2];Competition()}public void run()Random r = new Random();for(int a= 0;a<500;a++)for(int j = 0;j<2;j++)Speed[j] = r.nextInt(2);red = red + Speed[j];Speed[j] = r.nextInt(2);green = green + Speed[j];}System.out.println("red的速度为"+red);System.out.println("green的速度为"+green);while(red >=500 || green>=500)if(red >=500)System.out.println("red先抵达终点线");}if(green >= 500)System.out.println("green先抵达终点线");}if(green ==500 && red ==500 )System.out.println("两个同时到达");}return;}}/*if(red >green)System.out.println("Redwin"+red);}if(red<green)System.out.println("Greenwin"+green);}if(red == green)System.out.println("equal");*/JAVA的介绍:Java是一种可以撰写跨平台应用程序的面向对象的程序设计语言 。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群 。【java编程实例大全,java编程运算几个具体实例】

    推荐阅读