Thursday, September 2, 2010

Inverting Colors in Java

import java.util.Scanner;
import java.lang.Math;

public class InvertColor {
  public static void main(String args[]) {
    int red, green, blue;
    Scanner input = new Scanner(System.in);
    System.out.print("Enter the value for \"red\": ");
    red = input.nextInt();
    while (red > 255 || red < 0) {
      System.out.print("You must input a value between or equal to 0 and 255: ");
      red = input.nextInt();
    }
    System.out.print("Enter the value for \"green\": ");
    green = input.nextInt();
    while (green > 255 || green < 0) {
      System.out.print("You must input a value between or equal to 0 and 255: ");
      green = input.nextInt();
    }
    System.out.print("Enter the value for \"blue\": ");
    blue = input.nextInt();
    while (blue > 255 || blue < 0) {
      System.out.print("You must input a value between or equal to 0 and 255: ");
      blue = input.nextInt();
    }
    red = Math.abs(red-255);
    green = Math.abs(green-255);
    blue = Math.abs(blue-255);
    System.out.println("The inverted color for yours is:");
    System.out.println("Red: "+red);
    System.out.println("Green: "+green);
    System.out.println("Blue: "+blue);
  }
}

I can't believe I actually remember some of this crap. :\

No comments:

Post a Comment