0% found this document useful (0 votes)
2 views5 pages

Java Loops and Power Calculation Examples

The document contains code examples for using while loops, do-while loops, for loops, and calculating powers in Java. It includes 4 code snippets showing different loop implementations and calculating powers with user input.

Uploaded by

Andres Padilla
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)
2 views5 pages

Java Loops and Power Calculation Examples

The document contains code examples for using while loops, do-while loops, for loops, and calculating powers in Java. It includes 4 code snippets showing different loop implementations and calculating powers with user input.

Uploaded by

Andres Padilla
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

Ejercicio 1

package clase3;

public class Clase3 {

public static void main(String[] args) {

// TODO code application logic here

int i=5, suma=0;

while (i<=20)

[Link]("N: "+i);

suma=suma+i;

i=i+5;

[Link]("N: "+suma);

}
Ejercicio 2

package clase3;

public class Clase3 {

public static void main(String[] args) {

int i=5, suma=0;

do

[Link]("N: "+i);

suma=suma+i;

i=i+5;

while (i<=20);

[Link]("N: "+suma);

}
Ejercicio 3

package clase3;

import [Link];

public class Clase3 {

public static void main(String[] args) {

// TODO code application logic here

int i,suma=3;

for (i=1;i<=3;i++);

suma=suma+i*i+5;

[Link]("N: "+(suma+5));

}
Problema 1

package clase3;

import [Link];

public class Clase3 {

public static void main(String[] args) {

// TODO code application logic here

int base,exp,i=1,pot=1;

base=[Link]([Link]("Ingrese Base: "));

exp=[Link]([Link]("Ingrese exponente: "));

while(i<=exp)

pot=pot*base;

i++;{

[Link]("La Potencia es: "+pot);

}
package clase3;

import [Link];

public class Clase3 {

public static void main(String[] args) {

// TODO code application logic here

int base ,exp,i=1,pot=1;

base=[Link]([Link]("Ingrese Base: "));

exp=[Link]([Link]("Ingrese exponente: "));

for(i=1;i<=exp;i++)

pot=pot*base;

i++;{

[Link]("La Potencia es: "+pot);

You might also like