导航:首页 > 源码编译 > java卡五星算法

java卡五星算法

发布时间:2022-05-24 07:36:18

⑴ 请大家推荐几本关于java算法的最新书籍,非常感谢。

初级为了看懂可以看:算法设计与分析(第三版)这本高校教材。这本是Java写的,把上面每个算法研究清楚,

后期为了拓展可以看Java数据结构与算法分析等。淘宝直接搜索就可以知道书的具体信息
到了比较大神级的可以拓展看算法导论、编程之美这些大牛书籍。

⑵ java 算法,请问这是什么算法啊

Math.sqrt(i)是强制取整,你可以直接把这句话理解为while(j <= i){...
限制条件j<=i 是为了避免重复运算 比如j=3,i=5的情况 跟j=5,i=3的情况 后者就没必要去验证了对不对?这样可以提高程序效率。

⑶ 用java做算法好吗

java是建立在许多软件基础上的编程语言,对于算法程序的优化手段受到很大限制,这些都不利于做算法
可以考虑用c做算法,可以在兼顾可移植性的同时尽量优化,然后在java中调用。

⑷ java算法有哪些分别

您好:

java中的算法,常见的有:递归、迭代、查找、排序(包含冒泡排序、选择排序、插入排序、快速排序四种) 等,算法有很多,一般数据结构中涉及到的都可以用java语言实现。

举几个例子:

1.递归的例子:

不一一举例,仅供参考!

⑸ 谁能给我解释一下Java和Java的算法是什么意思,电脑啥也不懂,请大神用通俗易懂话解释

这个解释起来是有点难度的,不知道你的基础怎么样
Java是一种计算机编程语言,
Java的算法和其他编程语言的算法没有什么区别,都是用计算机数学的方式和逻辑来解决问题。
Java的算法的理解需要有一定的数学基础和计算机逻辑思维基础。
简单点理解,有点像解题,是比较复杂的数学题,需要用计算机能够理解和接受的方式来解题。

⑹ java中的算法,一共有多少种,哪几种,怎么分类。

就好比问,汉语中常用写作方法有多少种,怎么分类。

算法按用途分,体现设计目的、有什么特点
算法按实现方式分,有递归、迭代、平行、序列、过程、确定、不确定等等
算法按设计范型分,有分治、动态、贪心、线性、图论、简化等等

作为图灵完备的语言,理论上”Java语言“可以实现所有算法。
“Java的标准库'中用了一些常用数据结构和相关算法.

像apache common这样的java库中又提供了一些通用的算法

⑺ Java的数组的几种经典算法

JAVA中在运用数组进行排序功能时,一般有四种方法:快速排序法、冒泡法、选择排序法、插入排序法。
快速排序法主要是运用了Arrays中的一个方法Arrays.sort()实现。
冒泡法是运用遍历数组进行比较,通过不断的比较将最小值或者最大值一个一个的遍历出来。
选择排序法是将数组的第一个数据作为最大或者最小的值,然后通过比较循环,输出有序的数组。
插入排序是选择一个数组中的数据,通过不断的插入比较最后进行排序。下面我就将他们的实现方法一一详解供大家参考。
<1>利用Arrays带有的排序方法快速排序

public class Test2{ public static void main(String[] args){ int[] a={5,4,2,4,9,1}; Arrays.sort(a); //进行排序 for(int i: a){ System.out.print(i); } } }

<2>冒泡排序算法

public static int[] bubbleSort(int[] args){//冒泡排序算法 for(int i=0;i<args.length-1;i++){ for(int j=i+1;j<args.length;j++){ if (args[i]>args[j]){ int temp=args[i]; args[i]=args[j]; args[j]=temp; } } } return args; }

<3>选择排序算法

public static int[] selectSort(int[] args){//选择排序算法 for (int i=0;i<args.length-1 ;i++ ){ int min=i; for (int j=i+1;j<args.length ;j++ ){ if (args[min]>args[j]){ min=j; } } if (min!=i){ int temp=args[i]; args[i]=args[min]; args[min]=temp; } } return args; }

<4>插入排序算法

public static int[] insertSort(int[] args){//插入排序算法 for(int i=1;i<args.length;i++){ for(int j=i;j>0;j--){ if (args[j]<args[j-1]){ int temp=args[j-1]; args[j-1]=args[j]; args[j]=temp; }else break; } } return args; }

⑻ 如何用java写一个算法

是指一个类调用另一个类的么?
如果是这样的话。。
//创建一个类
public class Text1{
public static void mian(String []agrs){
//实例化另一个类
Text2 t = new Text2();
t.show();
}
}
创建第二个类
public class Text2(){
//创建一个show方法
public void show(){
System.out.println("我已经被调用了");
}
}
这就是类之间的调用。。
如果是想在方法里调用另一个类的方法
具体的也是和main()方法里的一样调用。(模仿main()方法)

⑼ java面试有哪些算法

面试-java算法题:
1.编写一个程序,输入n,求n!(用递归的方式实现)。
public static long fac(int n){ if(n<=0) return 0; else if(n==1) return 1; else return n*fac(n-1);
} public static void main(String [] args) {
System.out.println(fac(6));
}
2.编写一个程序,有1,2,3,4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
public static void main(String [] args) { int i, j, k; int m=0; for(i=1;i<=4;i++) for(j=1;j<=4;j++) for(k=1;k<=4;k++){ if(i!=j&&k!=j&&i!=k){
System.out.println(""+i+j+k);
m++;
}
}
System.out.println("能组成:"+m+"个");
}
3.编写一个程序,将text1.txt文件中的单词与text2.txt文件中的单词交替合并到text3.txt文件中。text1.txt文件中的单词用回车符分隔,text2.txt文件中用回车或空格进行分隔。
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class text{
public static void main(String[] args) throws Exception{
String[] a = getArrayByFile("text1.txt",new char[]{'\n'});
String[] b = getArrayByFile("text2.txt",new char[]{'\n',' '});
FileWriter c = new FileWriter("text3.txt");
int aIndex=0; int bIndex=0;

while(aIndex<a.length){
c.write(a[aIndex++] + "\n");
if(bIndex<b.length)
c.write(b[bIndex++] + "\n");
}

while(bIndex<b.length){
c.write(b[bIndex++] + "\n");
}
c.close();
}

public static String[] getArrayByFile(String filename,char[] seperators) throws Exception{
File f = new File(filename);
FileReader reader = new FileReader(f);
char[] buf = new char[(int)f.length()];
int len = reader.read(buf);
String results = new String(buf,0,len);
String regex = null;
if(seperators.length >1 ){
regex = "" + seperators[0] + "|" + seperators[1];
}else{
regex = "" + seperators[0];
}
return results.split(regex);
}

}
4.639172每个位数上的数字都是不同的,且平方后所得数字的所有位数都不会出现组成它自身的数字。(639172*639172=408540845584),类似于639172这样的6位数还有几个?分别是什么?
这题采用的HashMap结构判断有无重复,也可以采用下题的数组判断。
public void selectNum(){
for(long n = 100000; n <= 999999;n++){
if(isSelfRepeat(n)) //有相同的数字,则跳过
continue;
else if(isPingFangRepeat(n*n,n)){ //该数的平方中是否有与该数相同的数字
continue;
} else{ //符合条件,则打印 System.out.println(n);
}
}
} public boolean isSelfRepeat(long n){
HashMap<Long,String> m=new HashMap<Long,String>(); //存储的时候判断有无重复值
while(n!=0){ if(m.containsKey(n%10)){ return true;
} else{
m.put(n%10,"1");
}
n=n/10;
} return false;
} public boolean isPingFangRepeat(long pingfang,long n){
HashMap<Long,String> m=new HashMap<Long,String>(); while(n!=0){
m.put(n%10,"1");
n=n/10;
} while(pingfang!=0){ if(m.containsKey(pingfang%10)){ return true;
}
pingfang=pingfang/10;
} return false;
} public static void main(String args[]){ new test().selectNum();
}
5.比如,968548+968545=321732732它的答案里没有前面两个数里的数字,有多少这样的6位数。
public void selectNum(){
for(int n = 10; n <= 99;n++){
for(int m = 10; m <= 99;m++){ if(isRepeat(n,m)){ continue;
} else{
System.out.println("组合是"+n+","+m);
}
}
}
} public boolean isRepeat(int n,int m){ int[] a={0,0,0,0,0,0,0,0,0,0}; int s=n+m; while(n!=0){
a[n%10]=1;
n=n/10;
} while(m!=0){
a[m%10]=1;
m=m/10;
} while(s!=0){ if(a[s%10]==1){ return true;
}
s=s/10;
} return false;
} public static void main(String args[]){ new test().selectNum();
}
6.给定String,求此字符串的单词数量。字符串不包括标点,大写字母。例如 String str="hello world hello hi";单词数量为3,分别是:hello world hi。
public static void main(String [] args) { int count = 0;
String str="hello world hello hi";
String newStr="";
HashMap<String,String> m=new HashMap<String,String>();
String [] a=str.split(" "); for (int i=0;i<a.length;i++){ if(!m.containsKey(a[i])){
m.put(a[i],"1");
count++;
newStr=newStr+" "+a[i];
}
}
System.out.println("这段短文单词的个数是:"+count+","+newStr);
}
7.写出程序运行结果。
public class Test1 { private static void test(int[]arr) { for (int i = 0; i < arr.length; i++) { try { if (arr[i] % 2 == 0) { throw new NullPointerException();
} else {
System.out.print(i);
}
} catch (Exception e) {
System.out.print("a ");
} finally {
System.out.print("b ");
}
}
}
public static void main(String[]args) { try {
test(new int[] {0, 1, 2, 3, 4, 5});
} catch (Exception e) {
System.out.print("c ");
}
}

}
运行结果:a b 1b a b 3b a b 5b
public class Test1 { private static void test(int[]arr) { for (int i = 0; i < arr.length; i++) { try { if (arr[i] % 2 == 0) { throw new NullPointerException();
} else {
System.out.print(i);
}
}
finally {
System.out.print("b ");
}
}
}
public static void main(String[]args) { try {
test(new int[] {0, 1, 2, 3, 4, 5});
} catch (Exception e) {
System.out.print("c ");
}
}

}
运行结果:b c
8.单词数
统计一篇文章里不同单词的总数。
Input
有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。
Output
每组值输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。
Sample Input
you are my friend
#
Sample Output
4
public static void main(String [] args) {
List<Integer> countList=new ArrayList<Integer>(); int count;
HashMap<String,String> m;
String str; //读取键盘输入的一行(以回车换行为结束输入) String[] a;

Scanner in=new Scanner(System.in);
while( !(str=in.nextLine()).equals("#") ){
a=str.split(" ");
m=new HashMap<String,String>();
count = 0; for (int i=0;i<a.length;i++){ if(!m.containsKey(a[i]) && (!a[i].equals(""))){
m.put(a[i],"1");
count++;
}
}
countList.add(count);
}s for(int c:countList)
System.out.println(c);
}

⑽ 五子棋的Java算法

五子棋的算法是比较简单的。

把棋盘当作一个 2 维数组。 用2维数组来当作棋盘的坐标系

当落子 之后。 把落子,插入到 数组中 获得 棋盘 的数组, 循环刚才数组, 判断,

刚才 数组元素 的 横向坐标 -5 到刚才 数组元素坐标 + 5 是否都是 一个数字(黑子代表 1 ,白子代表0) 只要其中 有连续 5个 都是 黑子,或者白子, 则黑子或白子 赢了。

判断,刚才元素 纵向坐标 -5 到 + 5 如上判断。

判断 右斜线。 判断 横向坐标 -5 y -5 到 横向坐标 + 5 y + 5

判断 y + 5 x + 5 到 y-5 x -5

简单来说。

用2维数组 来代表 棋盘 , 每次在 界面上, 由白子,或黑子 落子之后, 在数组相应坐标,放入 1 或者0 。

然后循环数组判断, 数组横向 竖向 右斜线 左斜线 是否是 黑子或者白子 连续的。 如果是,则获胜。

阅读全文

与java卡五星算法相关的资料

热点内容
搬家服务app怎么开发 浏览:414
腾讯云外卖服务器 浏览:154
单片机1602显示程序 浏览:255
php检测网络 浏览:336
程序员面试金典第6版 浏览:718
内存2g编译安卓 浏览:414
单片机小数点怎么亮 浏览:414
安卓手机怎么设置健康码双击两下就出来 浏览:266
同一个文件夹可以存在两个相同的文件吗 浏览:535
动态重编译jit 浏览:132
android蓝牙音频 浏览:451
mc国际版怎么加服务器 浏览:816
phphtaccess配置 浏览:747
dos命令锁定 浏览:486
python中调换数据位置 浏览:300
武汉市中石油加油什么APP优惠 浏览:545
程序员33岁以后的规划 浏览:858
招标文件加密流转 浏览:897
源码数据盈利可信吗 浏览:860
android闪烁图标 浏览:942