Advertisement
apez1

Term 1: Lesson 14 - Coding Activity 3

Sep 25th, 2018
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.34 KB | None | 0 0
  1.  
  2.  
  3.  
  4.     import java.io.*;
  5. import static java.lang.System.*;
  6. import java.util.Scanner;
  7. import java.lang.Math;
  8.  
  9. public class Lesson_14_Activity_Three {
  10.       public static void main (String str []) throws IOException {
  11.    
  12.      Scanner scanner = new Scanner(System.in);
  13.  
  14.      int a;  
  15.      int b;
  16.      int c;  
  17.      int d;
  18.      int x;
  19.      
  20.      System.out.println("Please enter the first octet.");  
  21.      a = scanner.nextInt();
  22.      System.out.println("Please enter the second octet.");  
  23.      b = scanner.nextInt();
  24.      System.out.println("Please enter the third octet.");  
  25.      c = scanner.nextInt();
  26.      System.out.println("Please enter the fourth octet.");  
  27.      d = scanner.nextInt();
  28.      
  29.     x = 1;
  30.      
  31.     if(a >= 0 && a <= 255) {
  32.     }
  33.     else {
  34.      System.out.println("Octet 1 is incorrect");
  35.       x = 0;
  36.     }
  37.    
  38.     if(b >= 0 && b <= 255) {
  39.     }
  40.     else {
  41.      System.out.println("Octet 2 is incorrect");
  42.       x = 0;
  43.     }
  44.    
  45.     if(c >= 0 && c <= 255) {
  46.     }
  47.     else {
  48.      System.out.println("Octet 3 is incorrect");
  49.       x = 0;
  50.     }
  51.    
  52.     if(d >= 0 && d <= 255) {
  53.     }
  54.     else {
  55.      System.out.println("Octet 4 is incorrect");
  56.       x = 0;
  57.     }
  58.      
  59.    
  60.     if(x != 0) {
  61.      System.out.println("IP Address: " + a + "." + b + "." + c + "." + d);
  62.     }
  63.       }
  64.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement