Click here to load reader
Upload
edwin-belduma
View
238
Download
0
Embed Size (px)
Citation preview
UNIVERSIDAD TÉCNICA DE MACHALA
FACULTAD DE INGENIERÍA CIVIL ESCUELA DE INFORMÁTICA
CARRERA DE INGENIERÍA EN SISTEMAS
PROGRAMACION ESTRUCTURADA
AUTOR:
EDWIN EBER BELDUMA MOROCHO
PERIODO 2013 - 2014
MACHALA – EL ORO – ECUADOR
PRACTICA CON CONDICIONANTES EN JAVA
• DETERMINAR SI UN NUMERO ES MAYOR: • package principal;
• import java.util.Scanner;
• public class Condicionante {• public static void main(String[] args) {• Scanner sc = new Scanner(System.in);• System.out.println("INGRESE EL PRIMER NUMERO ");• int n1 = sc.nextInt();• System.out.println("INGRESE EL SEGUNDO NUMERO");• int n2 = sc.nextInt();• if (n1 > n2) {• System.out.println(" EL NUMERO MAYOR ES :" + n1);• } else {• System.out.println("EL NUMERO MAYOR ES : " + n2);• }• }
• }
• DETERMINAR SI UN NUMERO ES MAYOR CON 3 VARIABLES
• package principal;
• import java.util.Scanner;
• public class Numeromayor {• public static void main(String[] args) {• Scanner sc = new Scanner(System.in);• System.out.println("ingrese el primer numero");• double a = sc.nextDouble();• System.out.println("ingrese el segundo numero");• double b = sc.nextDouble();• System.out.println("ingreso el tercer numero");• double c = sc.nextDouble();
• if (a > b) {• if (a > c) {• System.out.println("el nuemero mayor es " + a);• } else {• System.out.println("el numero mayor es " + b);• }• } else {• if (b > c) {• System.out.println("el numero mayor es" + b);• } else {• System.out.println("el numero mayor es " + c);• }• }
• }
• }
• package principal;
• import java.util.Scanner;
• public class Condicionante2 {
• public class Deber {• public void main(String[] args) {• double r;• double raiz;• double m;• System.out.println("***MENU DE OPCION DE OPCIONES***");• System.out.println(" 1. SUMAR");• System.out.println(" 2. NUMERO PAR");• System.out.println(" 3. RAIZ CUADRADA POR PI");• System.out.println(" 4. MULTIPLICACION");• System.out.print("ingrese su opcion: ");• Scanner scan = new Scanner(System.in);• int n = scan.nextInt();• if (n == 0) {• System.out.println("esta opcion no existe");• } else if (n == 1) {• System.out.println(" 1. SUMAR");• System.out.println("ingrese el primer numero");• int n1 = scan.nextInt();• System.out.println("ingrese el segundo numero");• int n2 = scan.nextInt();• r = n1 + n2;• System.out.println("la suma es :" + r);
• } else if (n == 2) {• System.out.println(" 2. NUMERO PAR");• System.out.println("ingrese un numero");• int n3 = scan.nextInt();• if (n3 == 0) {• System.out.println("el numero ingresado es neutro");• } else if (n3 % 2 == 0) {• System.out.println("el numero ingresado es par");• } else {• System.out.println("el numero ingresado no es par");• }• } else if (n == 3) {• System.out.println(" 3. RAIZ CUADRADA POR PI");• System.out.println("ingrese un numero");• int n4 = scan.nextInt();• raiz = Math.sqrt((n4) * 3.1416);• System.out.println("el resultado es: " + raiz);• } else if (n == 4) {• System.out.println(" 4. MULTIPLICACION");• System.out.println("ingrese el primer numero");• int n5 = scan.nextInt();• System.out.println("ingrese el segundo numero");• int n6 = scan.nextInt();• m = n5 * n6;• System.out.println("la multiplicacion es: " + m);• } else {• System.out.println("esta opcion no existe");• }• }• }
• }
• package principal;
• import java.util.Scanner;
• public class Menu {• public static void main(String[] args) {• Scanner sc = new Scanner(System.in);• double a = 0;• double b = 0;• double r = 0;• int n = 0;
• System.out.println("MENU DE OPCIONES");• System.out.println("1.-OPICION SUMA");• System.out.println("2.-OPICION NUMERO PAR");• System.out.println("3.-OPCION RAIZ CUADRADA POR PI");• System.out.println("4.-OPCION MULTIPLICACION");• System.out.println("INGRESAR DATO NUMERICO A OPCION A REALIZAR");
• n = sc.nextInt();• if (n == 1) {• System.out.println("ingrese dos numeros a sumar");• a = sc.nextDouble();• b = sc.nextDouble();• r = a + b;• System.out.println("el resultado es" + r);• } else {• if (n == 2) {• System.out.println("ingrese numero para comprovacion de par");• a = sc.nextDouble();• if (a % 2 == 0) {• System.out.println("el numero es par");• } else {• System.out.println("el numero no es par");• }
• } else {• if (n == 3) {• System.out.println("ingrese un valor para raiz y x pi");• a = sc.nextDouble();• a = Math.sqrt(a) * 3.1416;• System.out.println("el resultado es " + a);• } else {• if (n == 4) {• System.out.println("ingrese 2 valores a multiplicar");• a = sc.nextDouble();• b = sc.nextDouble();• r = a * b;• System.out.println("resultado es :" + r);• } else {• System.out• .println("dato no valido ingrese dato 1 - 4 ");• }• }• }
• }
• }
• }
•ESPERO QUE ESTAS PRACTIACAS LES SIRVAN
GRACIAS ……