domingo, 21 de agosto de 2011

tablas


public class Tablas{
private int numeroTabla;
public Tablas(int nT){
this.numeroTabla=nT;
}
public void imprimirTabla() {
int i;
for(i=0;i<=10;i--){
System.out.println(" "+this.numeroTabla+"*"+i+"="+i*numeroTabla);

}
}
}
INICIo;

public class Inicio{
public static void main(String [] j){
Tablas t=new Tablas (20);
t.imprimirTabla ();
}
}


PROPIOimpropio


public class PropioImpropio{
private int numerador;
private int denominador;

public PropioImpropio (int n1,int n2){
this.numerador=n1;
this.denominador=n2;
}
public String getPropioImpropio(int n1,int n2){

if((n1>n2){
return(" el numero es Impropio");
}
else{
return("el numero es propio");
}
}
}

inicio:

import java.io.*;
public class Inicio {


public static void main(String[]args)throws IOException {
BufferedReader lectura = new BufferedReader(new InputStreamReader(System.in));

int num;
int dem;
PropioImpropio p = new PropioImpropio (2,4);

System.out.println("Ingrese numero 1: ");
num = Integer.parseInt(lectura.readLine());

System.out.println("Ingrese numero 2: ");
dem = Integer.parseInt(lectura.readLine());

System.out.println(p.getPropioImpropio());



}
}


PRIMOs


public class Primos{
private int numero;
public Primos(int n ) {
this.numero=n;

}
public String getPrimos(int n){
int c=0;
int i;

for(i=2; i<=n; i++){


if(n%i==0){
c=c+1;
}
if(c>2){
c=n;
}
if(c==1){
return("es primo");
}

else{
return ("el numero no es primo");
}

}

return("getPrimos");
 
      }      
}
INICIO;

import java.io.*;
public class Inicio {


public static void main(String[]args)throws IOException {
BufferedReader lectura = new BufferedReader(new InputStreamReader(System.in));

int n;
Primos  p1= new Primos (2);

System.out.println("Ingrese numero 1: ");
n = Integer.parseInt(lectura.readLine());
System.out.println(p1.getPrimos(3));
}
}


PitaGORAS


public class Pitagoras {
private double hipotenusa;
private int cateto1;
private double cateto2;

public Pitagoras(int c1,double c2){

this.cateto1=c1;
this.cateto2=c2;
}

public Pitagoras(double h, int c1){

this.hipotenusa=h;
this.cateto2=c1;
}

public double getHipotenusa(){
double hipotenusa;
hipotenusa=(Math.sqrt(this.cateto1*this.cateto1)+(this.cateto2*this.cateto2));
return( hipotenusa);
}

public double getCateto(){
double cateto;
cateto=(Math.sqrt(this.hipotenusa*this.hipotenusa)-(this.cateto1*this.cateto1));
return( cateto);
}
}

iNICIo:

public class Inicio{
public static void main (String [] w){
Pitagoras p1= new Pitagoras (50,15.0);
System.out.println("la hipotenusa es"+ (p1.getHipotenusa()));

Pitagoras p2= new Pitagoras (30.0,15);
System.out.println("el cateto es"+ (p2.getCateto()));
}
}


picas Y FIJAS


public class PicasYFijas {

private int n1;
private int n2;
private int n3;


public PicasYFijas (int n1, int n2, int n3){

this.n1 = n1;
this.n2 = n2;
this.n3 = n3;

}

public String getPicasYFijas(int nd1, int nd2, int nd3){

int p = 0;
int f = 0;

if ((n1 == nd1) && (n2 == nd2) && (n3 == nd3)){

return ("3 FIJAS");

}

else {

if (n1 == nd1){

f = f + 1;

}

if (n2 == nd2){

f = f + 1;

}

if (n3 == nd3){

f = f + 1;

}

if ((n1 == nd2) || (n1 == nd3)){

p = p + 1;

}

if ((n2 == nd1) || (n2 == nd3)){

p = p + 1;

}

if ((n3 == nd1) || (n3 == nd2)){

p = p + 1;

}

}

return ("Picas " + p + " Fijas " + f);

}
}

INICIO;

import java.io.*;
public class Inicio {


public static void main(String[]args)throws IOException {
BufferedReader lectura = new BufferedReader(new InputStreamReader(System.in));

int n1;
int n2;
int n3;

PicasYFijas pF = new PicasYFijas (3 , 2, 9);

System.out.println("Ingrese numero 1: ");
n1 = Integer.parseInt(lectura.readLine());

System.out.println("Ingrese numero 2: ");
n2 = Integer.parseInt(lectura.readLine());

System.out.println("Ingrese numero 3: ");
n3 = Integer.parseInt(lectura.readLine());

while (!pF.getPicasYFijas(n1, n2, n3).equals("3 FIJAS")){

System.out.println("Ingrese numero 1: ");
n1 = Integer.parseInt(lectura.readLine());

System.out.println("Ingrese numero 2: ");
n2 = Integer.parseInt(lectura.readLine());

System.out.println("Ingrese numero 3: ");
n3 = Integer.parseInt(lectura.readLine());

System.out.println(pF.getPicasYFijas(n1, n2, n3));

}

}
}

iMpAr


public class ImPar{
private int numero;
public ImPar( int num) {
this.numero=num;
        }
public String getImPar()
{
if(this.numero%2==0){
return("el numero es par");
}
else{
return("el numero es impar");
                }
}
}

iNiCio;

public class Inicio{
public static void main(String [] x){
        ImPar i1=new ImPar(67);
System.out.println(i1.getImPar());
        ImPar i2=new ImPar(40);
System.out.println(i2.getImPar());
ImPar i3=new ImPar(23);
System.out.println(i3.getImPar());
ImPar i4=new ImPar(98);
System.out.println(i4.getImPar());
}
}

FACTORIAL


public class Factorial {
private int n;

public Factorial (int n1) {
this.n=n1;
}

public String getFactorial (int n1) {
int i;
int r = 1;
for(i = 1; i <= n1; i++){
r=r* i;
}
return("El factorial es:" + r);
}

}

iNICIO:


import java.io.*;
public class Inicio {

public static void main (String [] args) throws IOException {
BufferedReader lectura = new BufferedReader(new InputStreamReader (System.in));


int n1;


System.out.println("ingrese numero factorial");
n1=Integer.parseInt(lectura.readLine());

Factorial f=new Factorial(n1);
System.out.println(f.getFactorial(n1));
}
}