import java.io.*;
public class Sushu
{
public static void main(String[] args)
{
String Str="";
System.out.println("请输入一个数:");
try{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
String s=in.readLine();
int n=Integer.parseInt(s);
for (int i=2;i<n ;i++ )
{
if(n%i==0)
{
Str="不是";
}
else
{
Str ="是";
}
}
System.out.println(n+Str+"素数");
}catch(IOException e){}
}
}不管输入什么数,输出的都说是素数!请问高手,错在哪里??是在if里面吗?
public class Sushu
{
public static void main(String[] args)
{
String Str="";
System.out.println("请输入一个数:");
try{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
String s=in.readLine();
int n=Integer.parseInt(s);
for (int i=2;i<n ;i++ )
{
if(n%i==0)
{
Str="不是";
}
else
{
Str ="是";
}
}
System.out.println(n+Str+"素数");
}catch(IOException e){}
}
}不管输入什么数,输出的都说是素数!请问高手,错在哪里??是在if里面吗?
解决方案 »
- [Microsoft][ODBC Microsoft Access 驱动程序] INSERT INTO 语句的语法错误。
- 关于Java中repaint()的问题
- java程序做成.exe的怎么做,大家推荐一个比较好的工具 我用的Eclipse
- JAVA虚拟机怎么用?急!在线等!
- 如何最快速的在程序中显示一个JComponent?
- Applet怎么显示不了啊
- 有什么办法可以让applet存取远程用户机器上的文件
- 一个关于在APPLET中调用JAVA SCRIPT CONFIRM对话框的问题,在线等待
- 请问如何将字符串转换成双精度数,紧急求救--才鸟
- httpcomponents-client-4.3.1 请求百度首页失败
- 在不修改文件内容的基础上添加内容 内容是分开的 在其中一个内容段后加 该怎么写
- 关于属小母牛的问题 改了一下cow.grow();的位置,结果咋就不一样了啊 ,想不明白啊 (从网上找的一个例子)
{
Str="不是";
break;
}
public static void main(String[] args) {
for (int i = 2; i <= 100; i++) {
boolean flag = true;
for (int j = 2; j <= Math.sqrt(i); j++) {
if (i % j == 0) {
flag = false;
break;
}
}
if (flag) {
System.out.print(i + " ");
}
}
}
}这是判断1-100之间有几个素数的写法
public class Sushu
{
public static void main(String[] args)
{
String Str="";
System.out.println("请输入一个数:");
try{
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
String s=in.readLine();
int n=Integer.parseInt(s);
for (int i=2;i<n ;i++ )
{
if(n%i==0)
{
Str="不是";
break;}//这样就可以了
else
{
Str ="是";
}
}
System.out.println(n+Str+"素数");
}catch(IOException e){}
}
}