0% found this document useful (0 votes)
32 views16 pages

Public Class Programa1 (

The document contains 11 Java programs that demonstrate the use of basic programming concepts like loops, arrays, methods, and classes. Program 1 prints the numbers from 0 to 99 using a for loop. Program 2 adds the numbers from 0 to 9 and prints the sum. Program 3 takes user input for two numbers and prints their sum. The programs increase in complexity, with later programs demonstrating two-dimensional arrays, methods for calculating totals and averages, and matrix operations.

Uploaded by

Vibmec123
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
32 views16 pages

Public Class Programa1 (

The document contains 11 Java programs that demonstrate the use of basic programming concepts like loops, arrays, methods, and classes. Program 1 prints the numbers from 0 to 99 using a for loop. Program 2 adds the numbers from 0 to 9 and prints the sum. Program 3 takes user input for two numbers and prints their sum. The programs increase in complexity, with later programs demonstrating two-dimensional arrays, methods for calculating totals and averages, and matrix operations.

Uploaded by

Vibmec123
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 16

Programa 1.

public class Programa1 {

public static void main(String[] args) {


int i=0;
for(i=0;i<100;i=i+1)
{
System.out.println("El numero es " +i);
}

System.out.println("");
System.out.println("fin del programa");
}
}
Programa 2.

public class Programa2 {

public static void main(String[] args) {


int i=0;
int Suma=0;
for(i=0;i<10;i=i+1)
{
System.out.println("El numero es " +i);
Suma=Suma + i;
}

System.out.println(" ");
System.out.println("Total = "+Suma);
System.out.println(" ");
System.out.println("Fin de programa");
}
}
Programa 3.

import java.util.Scanner;
public class Programa3 {

public static void main(String[] args) {


Scanner leer = new Scanner (System.in);
int suma=0, a=0,b=0,c=0;
System.out.println("Dame el Primer Valor");
a=leer.nextInt();
System.out.println("Dame el Segundo Valor");
b=leer.nextInt();
suma=a+b;
System.out.println("La suma es "+suma);
System.out.println(" ");
System.out.println("Fin de programa");

}
}
Programa 4.

import java.util.Scanner;
public class Programa4 {

public static void main(String[] args) {


Scanner leer=new Scanner (System.in);
int i=0, tabla=0;
System.out.println("Cual Tabla quieres Calcular");
System.out.println(" ");
tabla=leer.nextInt();
for(i=1;i<=10;i++)
{
System.out.println(tabla + "*" + i + " = " + tabla*i);
}

System.out.println(" ");
System.out.println("Fin del programa");
}
}
Programa 5.

import java.util.Scanner;
public class Programa5 {

public static void main(String[] args) {


Scanner leer=new Scanner (System.in);
int i=0, tabla=0, j=0;
System.out.println("Hasta cual Tabla vas a calcular");
System.out.println(" ");
tabla=leer.nextInt();
for(i=2;i<=tabla;i++)
{
for(j=1;j<=10;j++)
{

System.out.println(i + " * " + j + " = " + j*i);


}
System.out.println(" ");
}
System.out.println(" ");
System.out.println("Fin del programa");

}
}
Programa 6.

import java.util.Scanner;
public class Programa6 {

public static void main(String[] args) {


float suma,prom;
Scanner leer = new Scanner (System.in);
int a=0,b=0,c=0,d=0;
System.out.println("Dame el primer Valor");
a=leer.nextInt();
System.out.println("Dame el segundo Valor");
b=leer.nextInt();
System.out.println("Dame el tercer Valor");
c=leer.nextInt();
System.out.println("Dame el cuarto Valor");
d=leer.nextInt();
suma=a + b + c + d;
prom = (float) (suma/4.0);
System.out.println("La suma es " + suma);
System.out.println(" ");
System.out.println("El promedio es " + prom);
System.out.println(" ");
System.out.println("Fin de Programa");
}
}
Programa 7.

Import java.util.Scanner;
public class Programa7 {

public static void main(String[] args) {


Scanner leer = new Scanner (System.in);
int [] vector = new int[5];
int i=0, dato =0, total =0, promedio =0;
for(i=0;i<=4;i= i+1)
{
System.out.println("Capture el valor de ");
dato = leer.nextInt();
vector [i] = dato;
total= total + vector [i];
}

System.out.println(" ");
for(i=0;i<=4;i= i+1)
{
System.out.println("Valor del vector es " + vector [i] + " Indice " + i);
}
System.out.println(" ");
System.out.println("El total es " + total);
System.out.println(" ");
promedio = total / i;
System.out.println("El promedio es " + promedio);
System.out.println("Fin del programa ");

}
}
Programa 8.

import java.util.Scanner;
public class Programa8 {

public static void main(String[] args) {


Scanner leer = new Scanner (System.in);
int [][] matriz = new int [3][3];
int i =0, j =0, dato =0;
for(i=0;i<=2;i= i+1)
{
for(j=0;j<=2;j= j+1)
{
System.out.println("Capture el valor de la fila " +i);
dato = leer.nextInt();
matriz [i][j] = dato;
}
System.out.println(" ");
}
for(i=0;i<=2;i= i+1)
{
System.out.println(" ");
System.out.println("Valores de la fila " +i);
System.out.println(" ");
for(j=0;j<=2;j= j+1)
{
System.out.println("Valores de la fila " + matriz [i][j]);
}
}
System.out.println(" ");
System.out.println("Fin del Programa " );
}

}
Programa 9.

import java.util.Scanner;
public class Programa9 {

public static void main(String[] args) {


Scanner leer=new Scanner (System.in);
int[][] matriz = new int[4][4];
int i=0, j=0, dato=0, totalporFila=0;
for(i=0;i<=3;i=i+1)
{
for(j=0;j<=3;j=j+1)
{
System.out.println("Capture el valor de la fila " + 1);
dato = leer.nextInt();
matriz [i][j] = dato;
}
System.out.println(" " );
}
for(i=0;i<=3;i=i+1)
{
System.out.println(" " );
System.out.println("Valores de la Fila " + i);
System.out.println(" " );
for(j=0;j<=3;j=j+1)
{
System.out.println("Valores de la Fila " + matriz [i][j]);
totalporFila = totalporFila + matriz [i][j];
}
System.out.println("Total por Fila" + totalporFila);
totalporFila=0;
}
System.out.println(" " );
System.out.println("Fin del programa");

}
}
Programa 10.

import java.util.Scanner;
public class Programa10 {

public static void main(String[] args) {


Scanner leer=new Scanner (System.in);
int[][] matriz = new int[4][4];
int i=0, j=0, dato=0, totalporColumna=0;
for(i=0;i<=3;i = i+1)
{
for(j=0;j<=3;j=j+1)
{
System.out.println("Capture el valor de la Fila " + i);
dato=leer.nextInt();
matriz[i][j]=dato;
}
System.out.println(" " );
}
for(i=0;i<=3;i=i+1)
{
System.out.println(" " );
System.out.println("Valores de la Fila " + i);
System.out.println(" " );
for(j=0;j<=3;j=j+1)
{
System.out.println("Valores de la Fila " + matriz [i][j]);
totalporColumna=totalporColumna + matriz [j][i];
}
System.out.println("Total por Columna " + totalporColumna);
totalporColumna = 0;
}
System.out.println(" " );
System.out.println("Fin del programa " );
}

}
Programa 11.

import java.util.Scanner;
public class Programa11 {

public static void main(String[] args) {


Scanner leer = new Scanner (System.in);
int[][] matriz = new int [4][4];
int i=0, j=0, dato=0, totalporFila=0, totalporColumna=0;
for(i=0;i<=3;i=i+1)
{
for(j=0;j<=3;j=j+1)
{
System.out.println("Capture el valor de la fila " + i);
dato = leer.nextInt();
matriz [i][j] = dato;
}
System.out.println(" " );
}
for(i=0;i<=3;i=i+1)
{
System.out.println(" " );
System.out.println("Valores de la Fila " + i);
System.out.println(" " );
for(j=0;j<=3;j=j+1)
{
System.out.println(" Valores de la Fila " + matriz [i][j]);
totalporFila = totalporFila + matriz [i][j];
totalporColumna = totalporColumna + matriz [j][i];
}
System.out.println(" " );
System.out.println("TotalporFila " + totalporFila);
System.out.println("TotalporColumna " + totalporColumna);
totalporFila=0;
totalporColumna=0;
}
System.out.println(" " );
System.out.println("Fin del Programa ");
}
}

You might also like