parcial 2
programas en if y switch
programa de practica de if
/*
* 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 pkgif;
import java.util.*;
/**
*
* @author Usuario
*/
public class If {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int N;
System.out.print("introduce numero entero");
N= sc.nextInt();
if(N%2==0)
System.out.println("par");
else
System.out.println("impar");
// TODO code application logic here
}
}
programa de practica de switch
/*
* 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 shi;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Shi {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.print("ingresa el numero de un dia");
Scanner scanner = new Scanner(System.in);
int v=scanner.nextInt();
String dia;
switch(v){
case 1:
dia="lunes";
break;
case 2:
dia="martes";
break;
case 3:
dia="miercoles";
break;
case 4:
dia="jueves";
break;
case 5:
dia="viernes";
break;
case 6:
dia="sabado";
break;
case 7:
dia="domingo";
break;
default:
dia="Error no existe ese dia";
}System.out.println("el dia es "+ dia);
}
}
programa 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 pkgif;
import java.util.*;
/**
*
* @author Usuario
*/
public class If {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int N;
System.out.print("introduce numero entero");
N= sc.nextInt();
if(N%2==0)
System.out.println("par");
else
System.out.println("impar");
// TODO code application logic here
}
}
programa 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 pkg2;
import java.util.*;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int resto;
int numero1;
int numero2 =10;
System.out.print("introduce numero entero");
numero1= sc.nextInt();
resto= numero1%numero2;
if(resto==0)
System.out.println("el numero es multiplo de 10");
else
System.out.println("el numero no es multiplo de 10");
// TODO code application logic here
}
}
programa 3
/*
* 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 pkg3;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
System.out.print ("Ingrese un caracter: ");
char letra = teclado.nextLine().charAt(0);
if(Character.isUpperCase(letra)){
System.out.println("Mayuscula");
}else{
System.out.println("Minuscula");
}
}
}
programa 4
/*
* 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 pkg4;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
char N;
char x;
System.out.print("dame una letra");
N= sc.nextLine().charAt(0);
System.out.print("dame una letra");
x= sc.nextLine().charAt(0);
if(N==x)
System.out.println("es igual");
else
System.out.println("no es igual");
// TODO code application logic here
}
}
programa 5
/*
* 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 pkg5;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
System.out.print ("Ingrese un caracter: ");
char letra = teclado.nextLine().charAt(0);
System.out.print ("Ingrese un caracter: ");
char letra2 = teclado.nextLine().charAt(0);
if(Character.isUpperCase(letra)&& Character.isUpperCase(letra2)){
System.out.println("las dos son mayusculas");
}else{
System.out.println("una o las dos son minusculas");
}
}
}
programa 6
/*
* 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 pkg6;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner entrada=new Scanner (System.in);
int N;
System.out.print("dame un numero del 0 al 9");
N= entrada.nextInt();
if( N==0 || N==1 || N==2 || N==3 || N==4 || N==5 || N==6 || N==7 || N==8 || N==9){
System.out.println("el numero esta entre el 0 y el nueve");
}
else
{
System.out.println("el numero no esta en el 0 y el nueve");
}
// TODO code application logic here
}
}
programa 7
/*
* 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 pkg7;
import java.util.*;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
double N;
double d;
double r;
System.out.print("introduce numero entero");
N= sc.nextInt();
System.out.print("introduce el divisorio");
d= sc.nextInt();
if(d>0){
r=(N/d);
System.out.println("el resultado de la divicion es:"+ r);
}
else
{
System.out.println("el numero es negativo el de la divicion");
}
}
}
programa 8
/*
* 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 pkg8;
import java.util.*;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int n;
int a;
int b;
System.out.print("introduce el valor de n");
n= sc.nextInt();
System.out.print("introduce el valor de a");
a= sc.nextInt();
System.out.print("introduce el valor de b");
b= sc.nextInt();
if(n>a && n>b)
System.out.println("el mayor es n");
else
if(a>n && a>b)
System.out.println("el mayor es a");
else
if(b>n && b>a)
System.out.println("el mayor es b");
else
System.out.println("todos son iguales");
// TODO code application logic here
}
}
programa 9
/*
* 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 pkg9;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int h;
int m;
int s;
System.out.print("introduce las horas");
h= sc.nextInt();
System.out.print("introduce los minutos");
m= sc.nextInt();
System.out.print("introduce los segundos");
s= sc.nextInt();
if(h<=24 && m<=60 && s<=60)
System.out.println("el tiempo es valido");
else
System.out.println("el tiempo no es valido");
}
}
programa 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 pkg10;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.print("ingresa el numero del mes");
Scanner scanner = new Scanner(System.in);
int v=scanner.nextInt();
String dia;
switch(v){
case 1:
dia="enero"+31;
break;
case 2:
dia="febrero"+28;
break;
case 3:
dia="marzo"+31;
break;
case 4:
dia="abril"+30;
break;
case 5:
dia="mayo"+31;
break;
case 6:
dia="junio"+30;
break;
case 7:
dia="julio"+31;
break;
case 8:
dia="agosto"+31;
break;
case 9:
dia="septiembre"+30;
break;
case 10:
dia="octubre"+31;
break;
case 11:
dia="noviembre"+30;
break;
case 12:
dia="diciembre"+31;
break;
default:
dia="Error no existe ese mes";
}System.out.println("el el mes es "+ dia);
}
}
package ejemplo4;
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo4 {
public static void main(String[] args) {
boolean ejecutar= true;
int i=0;
while (ejecutar)
{
i++;
System.out.print(i+ ",");
if(i>=20){
ejecutar=false;
}
}
}
}
/*
* 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 pkgif;
import java.util.*;
/**
*
* @author Usuario
*/
public class If {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int N;
System.out.print("introduce numero entero");
N= sc.nextInt();
if(N%2==0)
System.out.println("par");
else
System.out.println("impar");
// TODO code application logic here
}
}
programa de practica de switch
/*
* 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 shi;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Shi {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.print("ingresa el numero de un dia");
Scanner scanner = new Scanner(System.in);
int v=scanner.nextInt();
String dia;
switch(v){
case 1:
dia="lunes";
break;
case 2:
dia="martes";
break;
case 3:
dia="miercoles";
break;
case 4:
dia="jueves";
break;
case 5:
dia="viernes";
break;
case 6:
dia="sabado";
break;
case 7:
dia="domingo";
break;
default:
dia="Error no existe ese dia";
}System.out.println("el dia es "+ dia);
}
}
programa 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 pkgif;
import java.util.*;
/**
*
* @author Usuario
*/
public class If {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int N;
System.out.print("introduce numero entero");
N= sc.nextInt();
if(N%2==0)
System.out.println("par");
else
System.out.println("impar");
// TODO code application logic here
}
}
programa 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 pkg2;
import java.util.*;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int resto;
int numero1;
int numero2 =10;
System.out.print("introduce numero entero");
numero1= sc.nextInt();
resto= numero1%numero2;
if(resto==0)
System.out.println("el numero es multiplo de 10");
else
System.out.println("el numero no es multiplo de 10");
// TODO code application logic here
}
}
programa 3
/*
* 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 pkg3;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
System.out.print ("Ingrese un caracter: ");
char letra = teclado.nextLine().charAt(0);
if(Character.isUpperCase(letra)){
System.out.println("Mayuscula");
}else{
System.out.println("Minuscula");
}
}
}
programa 4
/*
* 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 pkg4;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
char N;
char x;
System.out.print("dame una letra");
N= sc.nextLine().charAt(0);
System.out.print("dame una letra");
x= sc.nextLine().charAt(0);
if(N==x)
System.out.println("es igual");
else
System.out.println("no es igual");
// TODO code application logic here
}
}
programa 5
/*
* 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 pkg5;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado = new Scanner(System.in);
System.out.print ("Ingrese un caracter: ");
char letra = teclado.nextLine().charAt(0);
System.out.print ("Ingrese un caracter: ");
char letra2 = teclado.nextLine().charAt(0);
if(Character.isUpperCase(letra)&& Character.isUpperCase(letra2)){
System.out.println("las dos son mayusculas");
}else{
System.out.println("una o las dos son minusculas");
}
}
}
programa 6
/*
* 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 pkg6;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner entrada=new Scanner (System.in);
int N;
System.out.print("dame un numero del 0 al 9");
N= entrada.nextInt();
if( N==0 || N==1 || N==2 || N==3 || N==4 || N==5 || N==6 || N==7 || N==8 || N==9){
System.out.println("el numero esta entre el 0 y el nueve");
}
else
{
System.out.println("el numero no esta en el 0 y el nueve");
}
// TODO code application logic here
}
}
programa 7
/*
* 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 pkg7;
import java.util.*;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
double N;
double d;
double r;
System.out.print("introduce numero entero");
N= sc.nextInt();
System.out.print("introduce el divisorio");
d= sc.nextInt();
if(d>0){
r=(N/d);
System.out.println("el resultado de la divicion es:"+ r);
}
else
{
System.out.println("el numero es negativo el de la divicion");
}
}
}
programa 8
/*
* 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 pkg8;
import java.util.*;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int n;
int a;
int b;
System.out.print("introduce el valor de n");
n= sc.nextInt();
System.out.print("introduce el valor de a");
a= sc.nextInt();
System.out.print("introduce el valor de b");
b= sc.nextInt();
if(n>a && n>b)
System.out.println("el mayor es n");
else
if(a>n && a>b)
System.out.println("el mayor es a");
else
if(b>n && b>a)
System.out.println("el mayor es b");
else
System.out.println("todos son iguales");
// TODO code application logic here
}
}
programa 9
/*
* 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 pkg9;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
int h;
int m;
int s;
System.out.print("introduce las horas");
h= sc.nextInt();
System.out.print("introduce los minutos");
m= sc.nextInt();
System.out.print("introduce los segundos");
s= sc.nextInt();
if(h<=24 && m<=60 && s<=60)
System.out.println("el tiempo es valido");
else
System.out.println("el tiempo no es valido");
}
}
programa 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 pkg10;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.print("ingresa el numero del mes");
Scanner scanner = new Scanner(System.in);
int v=scanner.nextInt();
String dia;
switch(v){
case 1:
dia="enero"+31;
break;
case 2:
dia="febrero"+28;
break;
case 3:
dia="marzo"+31;
break;
case 4:
dia="abril"+30;
break;
case 5:
dia="mayo"+31;
break;
case 6:
dia="junio"+30;
break;
case 7:
dia="julio"+31;
break;
case 8:
dia="agosto"+31;
break;
case 9:
dia="septiembre"+30;
break;
case 10:
dia="octubre"+31;
break;
case 11:
dia="noviembre"+30;
break;
case 12:
dia="diciembre"+31;
break;
default:
dia="Error no existe ese mes";
}System.out.println("el el mes es "+ dia);
}
}
programas de los equipos
equipo 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 equipo1;
import java.awt.*;
/**
*
* @author CETIS100
*/
public class Equipo1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Frame f=new Frame ();
f.setVisible(true);
f.setSize(200,300);
f.setBackground(Color.blue);
}
}
equipo 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 equipo2;
/**
*
* @author CETIS100
*/
public class Equipo2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
boolean x= true;
boolean y= false;
boolean a1=x&&x;
boolean a2=x&&y;
boolean a3=y&&x;
boolean a4=y&&y;
System.out.println("tabla de la conjuncion");
System.out.println(x+".and."+x+"="+a1);
System.out.println(x+".and."+y+"="+a2);
System.out.println(y+".and."+x+"="+a3);
System.out.println(y+".and."+y+"="+a4);
}
}
* 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 equipo2;
/**
*
* @author CETIS100
*/
public class Equipo2 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
boolean x= true;
boolean y= false;
boolean a1=x&&x;
boolean a2=x&&y;
boolean a3=y&&x;
boolean a4=y&&y;
System.out.println("tabla de la conjuncion");
System.out.println(x+".and."+x+"="+a1);
System.out.println(x+".and."+y+"="+a2);
System.out.println(y+".and."+x+"="+a3);
System.out.println(y+".and."+y+"="+a4);
}
}
equipo 3
/*
* 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 equipo3;
/**
*
* @author Usuario
*/
public class Equipo3 {
public String nombre;
private int mes;
private int dia;
private int año;
public String apellido;
public Equipo3()
{
this.nombre ="javier";
this.apellido ="cajero";
this.mes = 5;
this.dia =19;
this.año =2002;
}
public void main(int dia) {
if(dia<35 && dia>0)
this.dia=dia;
// TODO code application logic here
}
public int getDia(){
return this.dia;
}
public void setMes(int mes) {
if(mes<13 && mes>0)
this.mes=mes;
}
public int getMes(){
return this.mes;
}
public void setAño(int año){
if(año<2019 && año>1950)
this.año=año;
}
public int getAño(){
return this.año;
}
}
* 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 equipo3;
/**
*
* @author Usuario
*/
public class Equipo3 {
public String nombre;
private int mes;
private int dia;
private int año;
public String apellido;
public Equipo3()
{
this.nombre ="javier";
this.apellido ="cajero";
this.mes = 5;
this.dia =19;
this.año =2002;
}
public void main(int dia) {
if(dia<35 && dia>0)
this.dia=dia;
// TODO code application logic here
}
public int getDia(){
return this.dia;
}
public void setMes(int mes) {
if(mes<13 && mes>0)
this.mes=mes;
}
public int getMes(){
return this.mes;
}
public void setAño(int año){
if(año<2019 && año>1950)
this.año=año;
}
public int getAño(){
return this.año;
}
}
en class
/*
* 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 equipo3;
/**
*
* @author Usuario
*/
public class actividad {
public static void main(String[]args){
Equipo3 persona=new Equipo3();
System.out.println(persona.nombre+" "+persona.getDia()+" del mes "+persona.getMes()+ " del año "+persona.getAño());
}
}
equipo 4
/*
* 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 equipo4;
public class Equipo4 {
private double balance= 0;
private double limit;
public void ingrsar(double cantidad)
{
balance=balance+cantidad;
}
void retirar(double cantidad) {
balance=balance-cantidad;
}
}
* 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 equipo4;
public class Equipo4 {
private double balance= 0;
private double limit;
public void ingrsar(double cantidad)
{
balance=balance+cantidad;
}
void retirar(double cantidad) {
balance=balance-cantidad;
}
}
equipo 5
/*
* 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 javaapplication1;
/**
*
* @author LAB-B-PC-8
*/
public class obra {
private String titulo;
private String autor;
public obra(String titulo, String autor)
{
this.titulo= titulo;
this.titulo= autor;
}
public void settitulo(String titulo)
{
this.titulo= titulo;
}
public void setautor(String autor)
{
this.autor= autor;
}
}
equipo 6
/*
* 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 equipo6;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Equipo6 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
double N,C,D;
System.out.println("ingresa un numero ");
N=sc.nextDouble();
C=Math.pow(N, 5);
D=Math.sqrt(C);
System.out.println("el resultado es"+D);
// TODO code application logic here
}
}
* 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 equipo6;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Equipo6 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
double N,C,D;
System.out.println("ingresa un numero ");
N=sc.nextDouble();
C=Math.pow(N, 5);
D=Math.sqrt(C);
System.out.println("el resultado es"+D);
// TODO code application logic here
}
}
equipo 7
/*
* 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 pkg7;
/**
*
* @author LAB-B-PC-8
*/
public class Main {
public static int numerador=10;
public static Integer denominador=0;
public static float division;
public static void main(String[] args) {
System.out.println("antes de hacer la division ");
try{
division = numerador / denominador;
}
catch (ArithmeticException ex){
division = 0;
System.out.println("error"+ex.getMessage());
}
finally{
System.out.println("division"+division);
System.out.println("despues de hacer la dision");
}
// TODO code application logic here
}
}
* 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 pkg7;
/**
*
* @author LAB-B-PC-8
*/
public class Main {
public static int numerador=10;
public static Integer denominador=0;
public static float division;
public static void main(String[] args) {
System.out.println("antes de hacer la division ");
try{
division = numerador / denominador;
}
catch (ArithmeticException ex){
division = 0;
System.out.println("error"+ex.getMessage());
}
finally{
System.out.println("division"+division);
System.out.println("despues de hacer la dision");
}
// TODO code application logic here
}
}
equipo 8
/*
* 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 equipo8;
/**
*
* @author CETIS100
*/
public class Equipo8 {
String nombre;
int edad;
public Equipo8(String _nombre,int _edad){
nombre=_nombre;
edad=_edad;
}
/**
* @param args the command line arguments
*/
public void mostrardatos() {
System.out.println("el nombre es"+nombre);
System.out.println("la edad es"+edad);
}
}
* 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 equipo8;
/**
*
* @author CETIS100
*/
public class Equipo8 {
String nombre;
int edad;
public Equipo8(String _nombre,int _edad){
nombre=_nombre;
edad=_edad;
}
/**
* @param args the command line arguments
*/
public void mostrardatos() {
System.out.println("el nombre es"+nombre);
System.out.println("la edad es"+edad);
}
}
equipo 9
/*
* 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 equipo10;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Equipo10 {
public Equipo10 (){
JLabel pideMensaje=new JLabel("dinos algo");
pideMensaje.setBounds(35,20,60,30);
JTextField campo=new JTextField(150);
campo.setBounds(35,60,180,30);
JButton boton= new JButton("da click");
boton.setBounds(35,140,150,30);
JLabel muestraMensaje=new JLabel();
muestraMensaje.setBounds(50,200,200,50);
ActionListener escuchador = new ActionListener(){
@Override
public void actionPerformed(ActionEvent ae) {
muestraMensaje.setText("dijiste esto"+campo.getText());
}
};
boton.addActionListener(escuchador);
add(muestraMensaje);
add(pideMensaje);
add(campo);
add(boton);
setSize(400,400);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
set.Visible(true);
}
public static void main(String[] args) {
new Newclass();
}
}
* 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 equipo10;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Equipo10 {
public Equipo10 (){
JLabel pideMensaje=new JLabel("dinos algo");
pideMensaje.setBounds(35,20,60,30);
JTextField campo=new JTextField(150);
campo.setBounds(35,60,180,30);
JButton boton= new JButton("da click");
boton.setBounds(35,140,150,30);
JLabel muestraMensaje=new JLabel();
muestraMensaje.setBounds(50,200,200,50);
ActionListener escuchador = new ActionListener(){
@Override
public void actionPerformed(ActionEvent ae) {
muestraMensaje.setText("dijiste esto"+campo.getText());
}
};
boton.addActionListener(escuchador);
add(muestraMensaje);
add(pideMensaje);
add(campo);
add(boton);
setSize(400,400);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
set.Visible(true);
}
public static void main(String[] args) {
new Newclass();
}
}
programa de ciclos
ejemplo 1
package ejemplo1;
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo1 {
public static void main(String[] args) {
// TODO code application logic here
int i=0;
for(i=3; i<=30; i++){
if((i%10)==3){
JOptionPane.showMessageDialog(null, "el valor de i es " +i);
}
}
}
}
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo1 {
public static void main(String[] args) {
// TODO code application logic here
int i=0;
for(i=3; i<=30; i++){
if((i%10)==3){
JOptionPane.showMessageDialog(null, "el valor de i es " +i);
}
}
}
}
ejemplo 2
package ejemplo2;
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo2 {
public static void main(String[] args) {
for (int j=0; j <=100;j++){
if ((j%3) ==0){
JOptionPane.showMessageDialog(null, "el valor de j es " +j);
}
else{
JOptionPane.showMessageDialog(null,+j+ "no es multiplo de 3");
}
}
}
}
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo2 {
public static void main(String[] args) {
for (int j=0; j <=100;j++){
if ((j%3) ==0){
JOptionPane.showMessageDialog(null, "el valor de j es " +j);
}
else{
JOptionPane.showMessageDialog(null,+j+ "no es multiplo de 3");
}
}
}
}
ejemplo 3
package ejemplo3;
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo3 {
public static void main(String[] args) {
int a=0;
for(int k=0; k<=4; k=k +2){
a++;
}
JOptionPane.showMessageDialog(null, "el valor de a es: " +a);
}
}
package ejemplo3;
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo3 {
public static void main(String[] args) {
int a=0;
for(int k=0; k<=4; k=k +2){
a++;
}
JOptionPane.showMessageDialog(null, "el valor de a es: " +a);
}
}
ejemplo 4
package ejemplo4;
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo4 {
public static void main(String[] args) {
boolean ejecutar= true;
int i=0;
while (ejecutar)
{
i++;
System.out.print(i+ ",");
if(i>=20){
ejecutar=false;
}
}
}
}
ejemplo 5
package ejemplo5;
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo5 {
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
int valor;
do{
System.out.print("ingrese el valor de 0 y 999(0 finaliza): ");
valor=teclado.nextInt();
if(valor>=100)
{
System.out.println("tiene 3 digitos");
}
else
{
if(valor>=10)
{
System.out.println("tiene 2 digitos");
}
else
{
System.out.println("tiene 1 digito");
}
}
}while(valor!=0);
}
}
import java.util.*;
import javax.swing.JOptionPane;
public class Ejemplo5 {
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
int valor;
do{
System.out.print("ingrese el valor de 0 y 999(0 finaliza): ");
valor=teclado.nextInt();
if(valor>=100)
{
System.out.println("tiene 3 digitos");
}
else
{
if(valor>=10)
{
System.out.println("tiene 2 digitos");
}
else
{
System.out.println("tiene 1 digito");
}
}
}while(valor!=0);
}
}
programa 1
package pkg4;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
double i;
double z;
double promedio=0;
for(i=0; i<=20; i++)
{
System.out.print("dame la calificacion del alumno");
z=teclado.nextInt();
if(z>8 && z<11){
}
promedio=(z*i)/20;
}
System.out.print("el promedio es"+promedio);
}
}
package pkg4;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
double i;
double z;
double promedio=0;
for(i=0; i<=20; i++)
{
System.out.print("dame la calificacion del alumno");
z=teclado.nextInt();
if(z>8 && z<11){
}
promedio=(z*i)/20;
}
System.out.print("el promedio es"+promedio);
}
}
programa 2
package pkg2v;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
double i;
double z;
double promedio=0;
int r=0;
int aslhey=0;
double pro8;
for(i=0; i<=20; i++)
{
System.out.print("dame la calificacion del alumno");
z=teclado.nextInt();
if(z<6)
{
r=r+1;
}
if(z>6){
aslhey=aslhey+1;
}
promedio=(z*i)/20;
}
System.out.print("el promedio es"+promedio);
System.out.print("los aprovados:"+aslhey);
System.out.print("la cantidad de reprovados:"+r);
}
}
package pkg2v;
import java.util.Scanner;
/**
*
* @author CETIS100
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
double i;
double z;
double promedio=0;
int r=0;
int aslhey=0;
double pro8;
for(i=0; i<=20; i++)
{
System.out.print("dame la calificacion del alumno");
z=teclado.nextInt();
if(z<6)
{
r=r+1;
}
if(z>6){
aslhey=aslhey+1;
}
promedio=(z*i)/20;
}
System.out.print("el promedio es"+promedio);
System.out.print("los aprovados:"+aslhey);
System.out.print("la cantidad de reprovados:"+r);
}
}
programa 3
package pkg3;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
double i;
double z;
double promedio=0;
int r=0;
int a=0;
double promedior=0;
double promedioa=0;
double pro=0;
int x;
for(i=0; i<=20; i++)
{
System.out.print("dame la calificacion del alumno");
z=teclado.nextInt();
if(z<=5)
{
r=r+1;
promedior=z*1/20;
}
if(z>=6){
a=a+1;
promedioa=z*1/20;
}
if(z>=8 && z<11){
pro=z*1/20;
}
promedio=(z*i)/20;
}
System.out.print("_el promedio es _"+promedio+"");
System.out.print("_promedio de arriba de ocho:_ "+pro);
System.out.print("_los que aprobaron:_ "+a+"");
System.out.print("_los que reprobaron:_"+r+"");
System.out.print("_promedio de los reprobados:_"+promedior+"");
System.out.print("_promedio de los aprobados:_"+promedioa+"");
}
}
package pkg3;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
double i;
double z;
double promedio=0;
int r=0;
int a=0;
double promedior=0;
double promedioa=0;
double pro=0;
int x;
for(i=0; i<=20; i++)
{
System.out.print("dame la calificacion del alumno");
z=teclado.nextInt();
if(z<=5)
{
r=r+1;
promedior=z*1/20;
}
if(z>=6){
a=a+1;
promedioa=z*1/20;
}
if(z>=8 && z<11){
pro=z*1/20;
}
promedio=(z*i)/20;
}
System.out.print("_el promedio es _"+promedio+"");
System.out.print("_promedio de arriba de ocho:_ "+pro);
System.out.print("_los que aprobaron:_ "+a+"");
System.out.print("_los que reprobaron:_"+r+"");
System.out.print("_promedio de los reprobados:_"+promedior+"");
System.out.print("_promedio de los aprobados:_"+promedioa+"");
}
}
programa 4
package programa4;
import java.util.Scanner;
public class Programa4 {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int i,a,b,c,d,e;
float prom,sum;
for (i=1; i<20; i++)
{
System.out.print("alumno..."+i+"calificacion 1...");
a = sc.nextInt();
System.out.print("alumno..."+i+"calificacion 1...");
b= sc.nextInt();
System.out.print("alumno..."+i+"calificacion 1...");
c= sc.nextInt();
System.out.print("alumno..."+i+"calificacion 1...");
d= sc.nextInt();
System.out.print("alumno..."+i+"calificacion 1...");
e= sc.nextInt();
sum=a+b+c+d+e;
prom=sum/5;
System.out.print("promedio del alumno"+i+"es:"+prom );
}
}
}
package programa4;
import java.util.Scanner;
public class Programa4 {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
int i,a,b,c,d,e;
float prom,sum;
for (i=1; i<20; i++)
{
System.out.print("alumno..."+i+"calificacion 1...");
a = sc.nextInt();
System.out.print("alumno..."+i+"calificacion 1...");
b= sc.nextInt();
System.out.print("alumno..."+i+"calificacion 1...");
c= sc.nextInt();
System.out.print("alumno..."+i+"calificacion 1...");
d= sc.nextInt();
System.out.print("alumno..."+i+"calificacion 1...");
e= sc.nextInt();
sum=a+b+c+d+e;
prom=sum/5;
System.out.print("promedio del alumno"+i+"es:"+prom );
}
}
}
programa 5
package pkg5;
import java.util.Scanner;
import javax.swing.JOptionPane;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int c;
do{
Scanner teclado=new Scanner (System.in);
System.out.print("dame la contraseña");
c=teclado.nextInt();
if(c<4567 || c>4567)
{
System.out.println("contraseña incorrecta");
}
}while(c!=4567);System.out.print("contraseña correcta");
}
}
import java.util.Scanner;
import javax.swing.JOptionPane;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int c;
do{
Scanner teclado=new Scanner (System.in);
System.out.print("dame la contraseña");
c=teclado.nextInt();
if(c<4567 || c>4567)
{
System.out.println("contraseña incorrecta");
}
}while(c!=4567);System.out.print("contraseña correcta");
}
}
programa 6
package pkg6;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int c;
int cd;
do{
Scanner teclado=new Scanner (System.in);
System.out.print("dame la contraseña");
c=teclado.nextInt();
System.out.print("dame el codigo");
cd=teclado.nextInt();
if(c<4567 || c>4567 || cd>1024 || cd<1024)
{
System.out.println("contraseña o codigo incorrectos");
}
}while(c!=4567 || cd!=1024);System.out.print("contraseña y codigo correctos");
}
}
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int c;
int cd;
do{
Scanner teclado=new Scanner (System.in);
System.out.print("dame la contraseña");
c=teclado.nextInt();
System.out.print("dame el codigo");
cd=teclado.nextInt();
if(c<4567 || c>4567 || cd>1024 || cd<1024)
{
System.out.println("contraseña o codigo incorrectos");
}
}while(c!=4567 || cd!=1024);System.out.print("contraseña y codigo correctos");
}
}
programa 7
package pkg7;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int x;
int y;
int c;
do{
Scanner teclado=new Scanner (System.in);
System.out.print("dame un numero positivo");
x=teclado.nextInt();
System.out.print("dame un numero positivo");
y=teclado.nextInt();
if(x>0 || y>0)
{
c=x+y;
System.out.println("la suma es " +c);
}
}while(x>=0 || y>=0);System.out.print("salio del programa");
}
}
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int x;
int y;
int c;
do{
Scanner teclado=new Scanner (System.in);
System.out.print("dame un numero positivo");
x=teclado.nextInt();
System.out.print("dame un numero positivo");
y=teclado.nextInt();
if(x>0 || y>0)
{
c=x+y;
System.out.println("la suma es " +c);
}
}while(x>=0 || y>=0);System.out.print("salio del programa");
}
}
programa 8
package pkg8;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
int i;
int z;
for(i=2; i<=12; i=i+2){
System.out.print("."+i);
}
for(z=2; z<=120; z=z*2){
System.out.print("."+z);
}
}
}
package pkg8;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner teclado=new Scanner (System.in);
int i;
int z;
for(i=2; i<=12; i=i+2){
System.out.print("."+i);
}
for(z=2; z<=120; z=z*2){
System.out.print("."+z);
}
}
}
programa 9
examen
/*
* 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 examencorrecto;
import javax.swing.JOptionPane;
import java.util.Scanner;
/**
*
* @author Usuario
*/
public class Examencorrecto {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner entrada = new Scanner (System.in);
int a,d1,d2,d3,d4,d5,valor;
System.out.print("dame un numero de 5 cifras");
a=entrada.nextInt();
if(a>10000){
d1= a %10/1;
d2= a %100/10;
d3= a %1000/100;
d4= a %10000/1000;
d5= a %100000/10000;
valor=(d1*10000)+(d2*1000)+(d3*100)+(d4*10)+(d5*1);
JOptionPane.showMessageDialog(null,"gracias por participar"+valor);
}
else{
JOptionPane.showMessageDialog(null,"no");
}
}
}
No hay comentarios.:
Publicar un comentario