Created
July 11, 2022 07:36
-
-
Save eduardojesus12/9278344fb84aa09446dd6e7bbb38c773 to your computer and use it in GitHub Desktop.
Código de otros 5
This file contains hidden or 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
public class Codigo5 { | |
Scanner s = new Scanner(); | |
System.out.print("Introduzca un número: '); | |
String ni = s.nextLine(); | |
int c = ni; | |
int afo = 0; | |
int noAfo = 0; | |
while (ni > 0) { | |
int digito = (int)(ni % 10); | |
if ((digito == 3) || (digito == 7) || (digito == 8) || (digito == 9)) { | |
afo++; | |
} else { | |
noAfo++; | |
ni /= 10; | |
} | |
if (afo > noAfo) { | |
System.out.prinln("El " + c + " es un número afortunado."); | |
} else { | |
System.out.println("El " + c + " no es un número afortunado."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Falta el paquete
import java.util.Scanner; Importamos herramienta scanner
public class Codigo5 {
public class static void main (String[] args) { // clase main faltaba
Scanner s = new Scanner(System.in ); // instanciamos
System.out.print("Introduzca un número: ');
int ni = s.next(); // Queremos guardar un numero
String c = ni;
int afo = 0;
int noAfo = 0;