Sie sind auf Seite 1von 10

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ex.e.pkg1;

import java.util.Scanner;

/**
*
* @author USER
*/
public class EXE1 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int n;
Scanner Leer=new Scanner(System.in);
System.out.println ("Introduzca la dimension de la matriz (IMPAR)");
n=Leer.nextInt();
int[][] M = new int [n+1][n+1];
matriz_f (M,n);
mostrar_matriz (M,n);
}

private static void mostrar_matriz(int[][] M, int n) {


for (int i=1;i<=n;i++)
{
System.out.print ("\n");
for (int j=1;j<=n;j++)
{
System.out.print ("\t [" +M[i][j]+ "]");
}
}
System.out.print ("\n");
}

private static void matriz_f(int[][] M, int n) {


int aux;
if (n%2==1)
{aux=(n+1)/2;
for(int i=1;i<=n;i++)
{
M[i][aux]=2;
}
for (int i=1;i<=n;i++)
{
M[aux][i]=2;
}
M[aux][aux]=1;
}
else
{
System.out.println ("n no es impar!!");
System.exit(0);
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ex.e.pkg2;

import java.util.Scanner;

/**
*
* @author USER
*/
public class EXE2 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int n;
Scanner Leer=new Scanner(System.in);
System.out.println ("Introduzca la dimension de la matriz");
n=Leer.nextInt();
int[][] M = new int [n+2][n+2];
matriz_f (M,n);
mostrar_matriz (M,n);
}

private static void mostrar_matriz(int[][] M, int n) {


for (int i=1;i<=n;i++)
{
System.out.print ("\n");
for (int j=1;j<=n;j++)
{
System.out.print ("\t [" +M[i][j]+ "]");
}
}
System.out.print ("\n");
}

private static void matriz_f(int[][] M, int n) {


int num=0,k=0,h=1;

for (int i=(n-1);i>0;i--)


{
M[1][n]=1;
M[1][i]=M[1][i+1]+(2*k+1);
k++;
}
while (h!=n)
{
for(int i=2;i<=n;i++)
{
M[i][n-h]=M[i-1][n-h]+1;
}
h++;
}
h=1;
for(int i=2;i<=n;i++)
{
for (int j=n-h;j<=n;j++)
{
M[i][j+1]=M[i][j]+1;
}
h++;
}

}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ex.e.pkg3;

import java.util.Scanner;

/**
*
* @author USER
*/
public class EXE3 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int n;
Scanner Leer=new Scanner(System.in);
System.out.println ("Introduzca un numero");
n=Leer.nextInt();
int[] V = new int [n+2];
vector_primos (V,n);
mostrar_vector (V,n);

private static void mostrar_vector(int[] V, int n) {


Scanner Leer=new Scanner(System.in);
for (int i=1;i<=n;i++)
{
System.out.print ("[" +V[i]+ "]");
}
System.out.println ("");
}

private static void vector_primos(int[] V, int n) {


int k=1,a;

for (int i=1;i<=n;i++)


{
a=0;
for (int j=1;j<=k;j++)
{
if(k%j==0)
{
a++;
}
}
if(a==2)
{
V[i]=k;
V[i+1]=k;
i++;
}
else
{
i--;
}
k=k+1;
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ex.e.pkg5;

import java.util.Scanner;

/**
*
* @author USER
*/
public class EXE5 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int n;
Scanner Leer=new Scanner(System.in);
System.out.println ("Introduzca la dimension de la matriz");
n=Leer.nextInt();
int[][] M = new int [n+1][n+1];
matriz_f (M,n);
mostrar_matriz (M,n);
}

private static void mostrar_matriz(int[][] M, int n) {


for (int i=1;i<=n;i++)
{
System.out.print ("\n");
for (int j=1;j<=n;j++)
{
System.out.print ("\t [" +M[i][j]+ "]");
}
}
System.out.print ("\n");
}

private static void matriz_f(int[][] M, int n) {


for (int i=1;i<=n;i++)
{
M[i][1]=1;
M[i][n]=1;
M[1][i]=1;
M[n][i]=1;
}
for (int i=2;i<n;i++)
{
for (int j=2;j<n;j++)
{
M[i][j]=2;
}
}

}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package ex.e.pkg4;

import java.util.Scanner;

/**
*
* @author USER
*/
public class EXE4 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int pp;
pp=lote();
System.out.println ("En el lote hay " +pp+ " numeros pares seguidos de un numero primo");
}

private static int lote() {


int x=-1,x1,x2,pp=0,a;
System.out.println ("Ingrese numeros en el lote");
do
{
x1=x;
Scanner Leer=new Scanner(System.in);
x=Leer.nextInt();
x2=x;
a=primos(x2);
if(x1%2==0 && a==1)
pp++;
}
while (x>=0);
return (pp);
}

private static int primos(int x2) {


int a=0;
for (int i=1;i<=x2;i++)
{
if (x2%i==0)
a++;
}
if (a==2)
a=1;
else
a=0;
return (a);
}

Das könnte Ihnen auch gefallen