## Java: Trying to get the sum of pairs that equal to a prime number

15 pts.
Tags:
Java
I am trying to get four input from the user and try to find pairs that equal to a prime number just by using user defined methods. I didn't reach the prime step yet. But before that I ran into a problem. So just to check the sum, I tried printing it out in the method called sumPair6 but it prints zero, so the sum is returning 0 for everything. Don't know what mistake I'm doing. I got rid of the initial 0 too but still doesn't not work.

Software/Hardware used:
import java.util.Scanner; public class prime { public static int num1 = 0, num2 = 0, num3 = 0, num4 = 0, sum1= 0,sum2,sum3,sum4,sum5,sum6,val1,stop; public static Scanner input = new Scanner(System.in); public static void main(String args[]) { input(); sumPair1(num1, num2, sum1); sumPair2(num1, num3, sum2); sumPair3(num1, num4, sum3); sumPair4(num2, num3, sum4); sumPair5(num2, num4, sum5); sumPair6(num3, num4, sum6); // Prime(sum1,sum2,sum3,sum4,sum5,sum6,val1,stop); } public static void input () { System.out.print(

Thanks. We'll let you know when a new response is added.

## Discuss This Question: 1 Reply

Thanks. We'll let you know when a new response is added.
• `this is my code`
```import java.util.Scanner;
public class prime
{
public static int  num1 = 0,  num2 = 0,  num3 = 0,  num4 = 0, sum1= 0,sum2,sum3,sum4,sum5,sum6,val1,stop;
public static Scanner input = new Scanner(System.in);
public static void main(String args[])
{
input();
sumPair1(num1, num2, sum1);
sumPair2(num1, num3, sum2);
sumPair3(num1, num4, sum3);
sumPair4(num2, num3, sum4);
sumPair5(num2, num4, sum5);
sumPair6(num3, num4, sum6);
// Prime(sum1,sum2,sum3,sum4,sum5,sum6,val1,stop);
}
public static void input ()
{
System.out.print("Enter a positive integer: ");
num1 = input.nextInt();
if(num1==0 || num1 < 0)
while(num1==0 || num1 < 0)
{
System.out.print("Enter a positive integer: ");
num1 = input.nextInt();
}
if(num1 > 0)

System.out.println("Thank you.");

System.out.print("Enter a positive integer: ");
num2 = input.nextInt();
if(num2==0 || num2 < 0)
while(num2 == 0 || num2 < 0)
{
System.out.print("Enter a positive integer: ");
num2 = input.nextInt();
}
if(num2 > 0)

System.out.println("Thank you.");

System.out.print("Enter a positive integer: ");
num3 = input.nextInt();
while(num3 ==0 || num3 < 0)
{
System.out.print("Enter a positive integer: ");
num3 = input.nextInt();
}
if(num3 > 0)

System.out.println("Thank you.");

System.out.print("Enter a positive integer: ");
num4 = input.nextInt();
if(num4==0 || num4 < 0)
while(num4 == 0 || num4 < 0)
{
System.out.print("Enter a positive integer: ");
num4 = input.nextInt();
}
if(num4 > 0)

System.out.println("Thank you.");

}
public static int sumPair1(int num1, int num2, int sum1)
{
sum1 = num1 + num2;
return sum1;
}

public static int sumPair2(int num1,int num3,int sum2)
{
sum2 = num1 + num3;
System.out.println(sum1);
return sum2;
}

public static int sumPair3(int num1, int num4,int sum3)
{
sum3 = num1 + num4;
return sum3;
}

public static int sumPair4(int num2, int num3,int sum4)
{
sum4 = num2 + num3;
return sum4;
}

public static int sumPair5(int num2,int num4,int sum5)
{
sum5 = num2 + num4;
return sum5;
}

public static int sumPair6(int num3, int num4,int sum6)
{
sum6 = num3 + num4;
System.out.println(sum1);
return sum6;
}
}
```