jeudi 6 octobre 2016

Trying to output an if else if, else loop. using arrays and Scanners. What am i doing wrong?

Trying to output an if else if, else loop. using arrays and Scanners, to create a very basic encryption program for an assignment. Using the scanner i can input integers, however the loop won't execute. What am i doing wrong?

 import java.util.Scanner;

 public class Question1A2 {

    public static void main (String [] args){

    Scanner S = new Scanner(System.in);

    System.out.println("\t-------------------------");
    System.out.println ("\tIO's 4-digit Encrypter");
    System.out.println("\t-------------------------");


 System.out.print("Please enter the four digit number you would like to encyrpt: ");

int[] arr = {S.nextInt(),S.nextInt(),S.nextInt(),S.nextInt()}; 

 int a = arr[0] %10 +7; 
 int b = arr[1] %10 +7;
 int c = arr[2]%10 +7;
 int d = arr [3] %10 +7;

 int i = arr.length; 

 for(;;){
  if  (arr.length > 9999) {
    System.out.println("Sorry, but that is not a four digit number. Program will terminate.");
      System.out.println("Thank you for using Zito's 4-digit Encrypter program.");
break;
  }

else if (arr.length < 1000) {
    System.out.println("Sorry, but that is not a four digit number. Program will terminate.");
  System.out.println("Thank you for using Zito's 4-digit Encrypter program.");
   break;
   }

 else {
 System.out.print("The encyrpted version of your input is ");

 System.out.print(a);
 System.out.print(b);
 System.out.print(c);
 System.out.print(d);

break;
}

     }
 }
}

Aucun commentaire:

Enregistrer un commentaire