Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.util.Scanner;
- public class NumeroTriangularFatorialPrimoMethodos {
- public static void main(String[] args) {
- Scanner Leitura=new Scanner(System.in);
- int numero=Leitura.nextInt();
- if(ÉPrimo(numero)) {
- System.out.println("É Primo\n");
- }
- else {
- System.out.println("Não é número Primo\n");
- }
- System.out.print("Seu fatorial é "+Fatorial(numero)+"\n");
- if(NumeroTriangular(numero)) {
- System.out.println("É um número triangular\n");
- }
- else {
- System.out.println("Não é um número triangular\n");
- }
- Leitura.close();
- }
- public static BigDecimal Fatorial (int numero) {
- int n = numero;
- BigDecimal fatorial = new BigDecimal(1);
- for ( int i = n; i > 0; --i ) {
- fatorial = fatorial.multiply(new BigDecimal(i));
- }
- return fatorial;
- }
- public static boolean ÉPrimo(int numero) {
- for (int j = 2; j < numero; j++) {
- if (numero % j == 0)
- return false;
- }
- return true;
- }
- public static boolean NumeroTriangular(int numero) {
- int variavel_auxiliar = 0;
- for(int i = 1 ; i*(i+1)*(i+2)<=numero ; i++)
- {
- if(i*(i+1)*(i+2)==numero)
- {
- variavel_auxiliar = 1;
- }
- }
- if(variavel_auxiliar==0) {
- return false;
- }
- else {
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement