zoukankan      html  css  js  c++  java
  • 回文与素数

    素数:

    public class Prime {
    public static void main(String[] args) {
    int b = 0;
    for (int i = 3; i <= 100; i++) {
    int a=2;
    for (int n = 2; n < i; n++) {
    if ((i % n) != 0) {
    a++;
    }
    }
    if (a == i) {
    b++;
    System.out.print(i + " ");
    if ((b % 5) == 0) {
    System.out.println();
    }
    }
    }
    System.out.println(" 共有" + b + "个质数");
    }
    }

    回文:

    import java.util.Scanner;
    public class Recurrence {
    public static void main(String[] args) {

    System.out.println("请输入字符串:");
    Scanner reader=new Scanner(System.in

    );
    String str=reader.next();
    int n=str.length();
    int m=huiwen(str,n);
    if(m==1)
    System.out.println("这个字符串是回文字符串!");
    else
    System.out.println("这个字符串不是回文字符串!");
    }
    public static int huiwen(String str,int n) {

    int a,b,j=0;
    char c1,c2;
    a=str.length()-n;
    b=str.length()-(a+1);
    c1=str.charAt(a);
    c2=str.charAt(b);
    if(c1==c2||a==b) j=1;
    if(a!=b&&a<b&&j==1)
    huiwen(str,n-1);
    return j;
    }
    }

  • 相关阅读:
    7.25
    7.24
    7.23
    7.22
    输入语句/条件运算符
    flowLayoutPanel1设置内容随着鼠标滚动而滚动
    dataGridView读取xml文件
    读文本内容 写入文本内容 创建复制文本
    cmd.ExecuteScalar 和配置连接设置
    $.ajax async同步加载
  • 原文地址:https://www.cnblogs.com/yishaui/p/9788708.html
Copyright © 2011-2022 走看看