Last active
March 21, 2019 10:35
-
-
Save AdryDev92/86c1a6be25860a8307dc4853a16a9763 to your computer and use it in GitHub Desktop.
Simple counter in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Contador{ | |
public static void main(String[] args) | |
{ | |
Scanner sc = new Scanner(System.in); | |
int cont=0, num=0, suma=0, longitud=0, input; | |
System.out.println("Introduce un numero:"); | |
input = sc.nextInt(); | |
counting(input); | |
} | |
//anotación | |
public static void counting(int longitud){ | |
int cont=0; | |
for (int i=1;i<=longitud ;i++ ) { | |
cont++; | |
System.out.println(i); | |
} | |
System.out.println("Has contado " + cont + " numeros"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class ContarCifras | |
{ | |
public static void main(String[] args) | |
{ | |
//anotación | |
Scanner input = new Scanner(System.in); | |
int numero, cifras; | |
cifras = 0; | |
System.out.println("Introduce un número entre 0 y 9999:"); | |
numero = input.nextInt(); | |
if (numero >= 0 && numero <= 9999) | |
{ | |
if (numero >= 0) | |
{ | |
cifras = cifras + 1; | |
numero = numero / 10; | |
} | |
if (numero > 0) | |
{ | |
cifras = cifras + 1; | |
numero = numero / 10; | |
} | |
if (numero > 0) | |
{ | |
cifras = cifras + 1; | |
numero = numero / 10; | |
} | |
if (numero > 0) | |
{ | |
cifras = cifras + 1; | |
numero = numero / 10; | |
} | |
System.out.println("El numero tiene " + cifras + " cifras."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now the counter receive a number by keyboard in this revision.