0% found this document useful (0 votes)
104 views

In Out: Package Import Public Class Public Static Void Throws Int New New

The document contains examples of Java code demonstrating the use of conditional statements (if/else), loops (for, while, do-while), and arrays (one-dimensional and two-dimensional) to practice basic programming concepts. Code snippets include input/output examples using if/else to check if a number is greater or less than 10, using for loops to calculate sums and print numbers, using while to calculate averages, and using arrays to store and manipulate data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

In Out: Package Import Public Class Public Static Void Throws Int New New

The document contains examples of Java code demonstrating the use of conditional statements (if/else), loops (for, while, do-while), and arrays (one-dimensional and two-dimensional) to practice basic programming concepts. Code snippets include input/output examples using if/else to check if a number is greater or less than 10, using for loops to calculate sums and print numbers, using while to calculate averages, and using arrays to store and manipulate data.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PRACTICA CON EL IF Y ELSE

package para_el;
import java.io.*;
public class examen {
public static void main(String[] args)throws Exception{
int a;
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (isr);
System.out.println("Ingrese primer digito: ");
a = Integer.parseInt(br.readLine());
if (a > 10){
System.out.println("El numero: " + a + " " + "Es mayor que DIEZ");
}else{
System.out.println("El numero: " + a + " " + "Es menor que DIEZ");
}
}
}
package para_el;
import java.io.*;
public class examen {

public static void main(String[] args)throws Exception{


int num;
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (isr);
System.out.println("Ingrese un numero: ");
num = Integer.parseInt(br.readLine());
if(num % 3 == 0 && num % 6 != 0)
System.out.println("Es multiplo solo de 3 pero no de 6");
else
System.out.println("No es multiplo solo de 3");
}

PRACTICA CON EL FOR


package para_el;
public class examen {
public static void main(String[] args)throws Exception{
int suma = 0;
for( int numero = 2; numero <= 100; numero += 2 )
suma += numero;

System.out.println("La suma es: " + suma);

package para_el;
public class examen {

public static void main(String[] args)throws Exception{


int x;
for(x = 1; x <= 10; x++){
if(x == 6)
break;//interrumpe el ciclo solo si x es 6
System.out.println(x + " ");
}
System.out.println("\nInterrupcion del ciclo cuando x se volvio " + x);
}

PRACTICA CON EL WHILE


package para_el;
import java.io.*;
public class examen {

public static void main(String[] args)throws Exception{


int prom;
int total;
int contadorCal;
int calificacion;
total = 0;
contadorCal = 1;
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (isr);
System.out.println("Introduzca calificacion: ");
calificacion = Integer.parseInt(br.readLine());
while(contadorCal <= 10){
total = total + calificacion;
contadorCal = contadorCal +1;
}
prom = total/10;
System.out.println("El promedio de la clase es: " + prom);
}

package para_el;

import java.io.*;
public class examen {
public static void main(String[] args)throws Exception{
int num, digSig;
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader br = new BufferedReader (isr);
System.out.println("Ingrese numero a invertir: ");
num = Integer.parseInt(br.readLine());
System.out.println("Numero en orden inverso: ");
do{
digSig = num % 10;
System.out.println(digSig);
num = num / 10;
}
while(num > 0);
}
}
PRACTICA CON ARRAYS UNIDIMENCIONAL
package para_el;
public class examen {

public static void main(String[] args)throws Exception{


int x;
float result = 0;
float arreglo[]= new float [10];
for (x=0; x<arreglo.length; x++){
arreglo[x]=x + 1000;
}
for (x=0; x<arreglo.length; x++){
result = result + arreglo[x];
}
System.out.println (result);
}

package para_el;
import java.io.*;
public class examen {
public static void main(String[] args)throws Exception{
int x;
float result = 0;
float arreglo[]= new float [10];

for (x=0; x<arreglo.length; x++){


arreglo[x]=x - 10;
}
for (x=0; x<arreglo.length; x++){
result = result - arreglo[x];
}
System.out.println (result);

ARRAYS BIDIMENCIONAL
package para_el;
import java.io.*;
public class examen {
public static void main(String[] args)throws Exception{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int matriz1 [][] = new int [4][3];
int matriz2 [][] = new int [4][3];
int result [][] = new int [4][3];
int fila,col;
for (fila = 0; fila < 4; fila++){
for (col = 0; col < 3; col++){
System.out.println ("Ingresar los datos de la matriz1
en la posicion" + fila + " , " + col);
matriz1 [fila][col] = Integer.parseInt(br.readLine());
}
}
for (fila = 0; fila < 4; fila++){
for (col = 0; col < 3; col++){
System.out.println ("Ingresar los datos de la matriz2
en la posicion" + fila + " , " + col);
matriz2 [fila][col] = Integer.parseInt(br.readLine());
}
}
for (fila = 0; fila < 4; fila++){
for (col = 0; col < 3; col++){
result [fila][col] = matriz1 [fila][col] - matriz2 [fila]
[col];
System.out.print (result [fila][col] + " ");
}
System.out.println (" ");
}
}

}
package para_el;
import java.io.*;
public class examen {
public static void main(String[] args)throws Exception{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
int matriz1 [][] = new int [4][3];
int matriz2 [][] = new int [4][3];
int result [][] = new int [4][3];
int fila,col;
for (fila = 0; fila < 4; fila++){
for (col = 0; col < 3; col++){
System.out.println ("Ingresar los datos de la matriz1
en la posicion" + fila + " , " + col);
matriz1 [fila][col] = Integer.parseInt(br.readLine());
}
}
for (fila = 0; fila < 4; fila++){
for (col = 0; col < 3; col++){
System.out.println ("Ingresar los datos de la matriz2
en la posicion" + fila + " , " + col);
matriz2 [fila][col] = Integer.parseInt(br.readLine());
}
}
for (fila = 0; fila < 4; fila++){
for (col = 0; col < 3; col++){
result [fila][col] = matriz1 [fila][col] * matriz2 [fila]
[col];
System.out.print (result [fila][col] + " ");
}
System.out.println (" ");
}
}
}

You might also like