小编bla*_*une的帖子

main java.lang.ArithmeticException:/ by Zero

我尝试了使用throw new方法来表示不能被零除的不同方法.

public class FractionDemo
{
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);
        Fraction f1 = new Fraction(), f2 = new Fraction(); 

        System.out.print("Enter the numerator for the target fraction:"); 
        int a = scan.nextInt(); 

        System.out.print("Enter the denominator for the target fraction:"); 
        int b = scan.nextInt(); 

        System.out.print("Enter the numerator for the next fraction to test:"); 
        int n = scan.nextInt(); 

        System.out.print("Enter the denominator for the next fraction to test:"); 
        int d = scan.nextInt(); 

        if(f1.equals(f2))
            System.out.print("The fraction you just entered …
Run Code Online (Sandbox Code Playgroud)

java

1
推荐指数
1
解决办法
5949
查看次数

printf不工作为什么?

没有编译器错误,但我没有看到printf语句(循环后).循环前的printf都很好.我想不出来解决这个问题.

   int prime(int n); 


    int main(void)
    {
        int num = 0; 
        bool prime; 
        int n; 
        int count; 
        int sum; 

        printf("Enter the limit:", n); 
        scanf("%d", &n);
        printf("Primes up to %d\n", n); 


        // loop 
        for(int i =2; i <= n; i++)
        {
            prime = true; 
            for(int j =2; j < i; j++)
            {
                if(i%j == 0)
                {
                    prime = false;
                    break; 
                }
            }
            if(prime)
            {
                num += i; 
                printf("%d ", i);

            }
        }
        return num;
        count++;
        sum += count; 
        // sum of …
Run Code Online (Sandbox Code Playgroud)

c

-3
推荐指数
1
解决办法
108
查看次数

标签 统计

c ×1

java ×1