I want a program that shows ask the user for numbers until you enter a "0" or a negative number, when this happens, the program should show: 1.-How many numbers are entered 2. How many are cousins 3. How many are pairs 4.- How many are odd.
I have made the code for cases 2,3, and 4. Can I join the code that I already have in some way? Honestly I have no idea what I need or where to proceed, since it is my first Java course. What should I learn to be able to solve this?
I have code for prime numbers:
package nprimo;
import java.util.Scanner;
public class Nprimo {
public static void main(String[] args) {
int temp;
boolean isPrime=true;
Scanner scan= new Scanner(System.in);
System.out.println("Ingrese un numero");
int num = scan.nextInt();
for (int i=2;i<=num/2;i++)
{
temp=num%i;
if (temp==0)
{
isPrime=false;
break;
}
}
if(isPrime)
System.out.println(num +"Es un numero primo :) ");
else
System.out.println(num +"No es un número primo :( ");
}
}
and the code to know if the number is even or odd.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int n;
String m="";
System.out.println("*Determinarn numero es par o impar*");
System.out.println("");
System.out.println("ingreseumero");
Scanner teclado=new Scanner(System.in);
n=teclado.nextInt();
if(n%2==0)
m="es par";
else
m="es impar";
System.out.println("elro "+n+" "+m);
}
}
Thank you.