Is that possible to make an if with 4 statements? I tried to do that, But for some reason it's getting bugged.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
String hexa;
int dec = 0;
int i = 0;
System.out.println("Please enter a hexa code.");
hexa = s.nextLine();
for(i=0; i < hexa.length(); i++) {
System.out.println("Index " + i);
if(((int)hexa.charAt(i) >= 48 && ((int)hexa.charAt(i) <= 57)) ||((int)hexa.charAt(i) >= 65 && (int)hexa.charAt(i) <= 70)
|| ((int)hexa.charAt(i) >= 97 && (int)hexa.charAt(i) <= 102))
{
dec = Integer.parseInt(hexa, 16);
}else{
System.out.println("Error! not a hexa code.");
break;
}
}
System.out.println("Decimal code is: " + dec);
}
}
Aucun commentaire:
Enregistrer un commentaire