我知道这不是什么大问题,但我讨厌我的程序在做什么.这是一个简单的程序,我写了一个程序,询问用户一个整数,然后打印出所有的因素.例如,当用户输入150时,程序应该打印2,3,5,5.
这是我的程序(它的工作原理)
import java.util.Scanner;
public class FirstProgram {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int number;
int divisor = 2;
System.out.println("Enter the number: ");
number = scan.nextInt();
while (number > 1) {
if ((number % (number / divisor)) == 0 && number > 0) {
number = number / divisor;
System.out.print(divisor);
if (number != 1)
System.out.print(", ");
}
else if ((number % (number / divisor)) != 0 && number > 1) {
divisor++;
if (number …Run Code Online (Sandbox Code Playgroud) 您好我们可以在Java 7中同时使用资源和多重捕获吗?我试图使用它,它给出了编译错误.我可能错误地使用它.请指正.
try(GZIPInputStream gzip = new GZIPInputStream(new FileInputStream(f));
BufferedReader br = new BufferedReader(new InputStreamReader(gzip))
{
br.readLine();
}
catch (FileNotFoundException | IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我试图找到甚至斐波纳契数的总和,直到400万.我找到了这些数字,但我无法将它们加起来......在if(n%2 == 0)循环中
8
34
144
610
2584
10946
46368
196418
832040
3524578
Run Code Online (Sandbox Code Playgroud)
public static void number2()
{
int number = 40;
int a, b, c;
int numLim = 0;
a = 1;
b = 2;
while(numLim < 4000000)
{
c = a + b;
a = b;
b = c;
numLim = b;
if(numLim > 4000000)
{
break;
}
int sum = 0;
if(numLim % 2 == 0)
{
System.out.println(numLim);
sum = sum + numLim;
System.out.println("sum :" +sum);
} …Run Code Online (Sandbox Code Playgroud) #include<stdio.h>
#include<conio.h>
#include<iostream>
using namespace std;
int main()
{
int i,a=4, b=3;
for (i=0, i<3, i++)
{
if (b%2==0)
{
printf("%d+%d=%d", a, b, a+b);
i++;
}
b++
}
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我需要帮助!每次我说它,它用以下内容说:
8预期';' 之前')'令牌"
我不知道该怎么办,请帮忙!