public class HelloWorld{ public static void main(String []args){ Pixel[][] arr = { {{0, 0, 100},{0,1,100},{0,2,100}{0,3,100}}, {{0, 0, 100},{0,1,100},{0,2,100}{0,3,100}}, {{0, 0, 100},{0,1,100},{0,2,100}{0,3,100}}, {{0, 0, 100},{0,1,100},{0,2,100}{0,3,100}} }; printArr(arr); } public static void printArr(Pixel[][] arr){ for(int i = 0, i < arr.length; i++){ for(int j = 0; j < arr[0].length; j++){ System.out.print(arr[i][j].toString() + " "); } System.out.println(); } } } public class Pixel { private int red; private int green; private int blue; public Pixel(int myRed, int myGreen, int myBlue) { red = myRed; green = myGreen; blue = myBlue; } public String toString() { return "(" + red + ", " + green + ", " + blue + ")"; } } public class AlterImage { /** Converts 3 arrays of color values into one array * of Pixel objects * * @param reds the red color values * @param greens the green color values * @param blues the blue color values * @return the Pixel array generated with information * in the red, green and blue arrays * * Precondition: The three color arrays are all the same * size and contain int values in the range 0-255. * Postcondition: The returned array is the same size as the * 3 color arrays. */ public Pixel[][] generatePixelArray(int[][] reds, int[][] greens, int[][] blues) { /* to be implemented in part (a) */ Pixel[][] result = new Pixel[reds.length][reds[0].length]; for(int r = 0; r < result.length; r++){ for(int c = 0; c < result[0].length; c++){ result[r][c] = new Pixel(reds[r][c], greens[r][c], blues[r][c]); } } return result; } /** Flips a 2D array of Pixel objects either * horizontally or vertically * * @param image the 2D array of Pixel objects to be processed * @param horiz true: flip horizontally, false: flip vertically * @return the processed image */ public Pixel[][] flipImage(Pixel[][] image, boolean horiz) { Pixel[][] result = new Pixel[image.length][image[0].length]; if(horiz){ for(int i = 0; i < image.length; i++){ for(int j = 0; j < image[0].length; j++){ result[image.length - i - 1][j] = image[i][j]; } } } else{ for(int i = 0; i < image.length; i++){ for(int j = 0; j < image[0].length; j++){ result[i][image[0].length - j -1] = image[i][j]; } } return result; } }
public class Bankkonto {/* Dieses Programm bildet die Funktionen eines Geldautomaten ab*/ public static void main(String[] args) { int kontostand = 300000000; int kreditlimit = -200; /* Betrag, um den das Konto maximal berzogen werden kann */ int auszahlung = 200000000; /* Hier wird eigegeben, wieviel vom Konto abgehoben werden soll*/ int kontostandNeu = kontostand - auszahlung; if (kontostand - auszahlung >= kreditlimit) { System.out.println("Es werden " + auszahlung + " Euro ausbezahlt."); System.out.println("Ihr aktueller Kontostand betraegt " + kontostandNeu + " Euro"); } else {System.out.print ("Der Vorgang kann nicht ausgefuehrt werden. Ihr Guthaben reicht leider nicht aus.");} } }
//Name - Isaiah Roman //Date: 4-9-19 import static java.lang.System.*; public class CardRunner { public static void main(String[] args) { TreeSet<Card> ss = new TreeSet<>(); ss.add(new BlackJackCard("two", Suit.Club)); ss.add(new BlackJackCard("five", Suit.Spade)); ss.add(new BlackJackCard("king", Suit.Heart)); ss.add(new BlackJackCard("jack", Suit.Diamond)); ss.add(new BlackJackCard("ace", Suit.Spade)); for (Card c : ss) { // System.out.println(c); } class BlackJackCard extends Card { public BlackJackCard (int s, int v) { super(s, v); suit = s; value = v; } public BlackJackCard(String s, String val){ super(s, val); } public int getValue() { if (value == 10) { return 10; } else if (value == 11) { return 10; } else if (value == 12) { return 10; } else if (value == 13) { return 10; } else { return value; } } }
public class pattern_pro5 { public static void main(String args[]) { for(int i=1;i<=5;i++) { for(int j=0;j<i;j++) { System.out.print("*"); } System.out.print("\n"); } } }
public class Bankkonto {/* Dieses Programm bildet die Funktionen eines Geldautomaten ab*/ public static void main(String[] args) { int kontostand = 30; int kreditlimit = -200; /* Betrag, um den das Konto maximal berzogen werden kann */ int auszahlung = 30; /* Hier wird eigegeben, wieviel vom Konto abgehoben werden soll*/ int kontostandNeu = kontostand - auszahlung; if (kontostand - auszahlung >= kreditlimit) { System.out.println("Es werden " + auszahlung + " Euro ausbezahlt."); System.out.println("Ihr aktueller Kontostand betrgt " + kontostandNeu + " Euro"); } else {System.out.print ("Der Vorgang kann nicht ausgefhrt werden. Ihr Guthaben reicht leider nicht aus.");} } }
/** * This simple program has one class: Bird (plus a main class) * The Bird definition has three attributes, two overriding constructors, * and a getter and setter for each attribute. * * Notice that the setter for attractiveness does a validity check * before it sets the value. This is part of the value of getters * and setters. They allows the object to control how its attributes are * accessed and changed. * * In reality, there would be additional methods, like fly(), * eat(), and buildNest(). * */ class Bird { //Instance Attributes: each object has its own private String species; // private: controlled by the object private String colour; private String attractiveness; //Constructors (overloaded, without and with parameters) public void Bird(){ species = ""; colour = ""; attractiveness = "pretty"; // default } public void Bird(String species, String colour, String attractiveness){ this.species = species; this.colour = colour; this.attractiveness = attractiveness; } //Getters and Setters public String getSpecies() { return species; } public void setSpecies(String species){ this.species = species; } public String getColour(){ return colour; } public void setColour(String colour){ this.colour = colour; } public String getAttractiveness(){ return attractiveness; } //The setter for attractiveness adjusts the input public void setAttractiveness(String attractiveness){ if(attractiveness == "nice"){ this.attractiveness = "pretty"; }else{ this.attractiveness = attractiveness; } } } public class Main { public static void main(String args[]) { Bird myBird = new Bird(); myBird.setSpecies("Jay"); myBird.setColour("blue"); myBird.setAttractiveness("nice"); System.out.println("The bird is a " + myBird.getSpecies() + "."); System.out.println("The bird is " + myBird.getColour() + "."); System.out.println("The bird is " + myBird.getAttractiveness() + "."); } }
import java.util.*; public class Sort{ //static Scanner sc=new Scanner(System.in); public static void main(String []args){ double [] lista ={6,3,8,1,5}; //skriv ut den osorterade arrayen /* for(int i = 0; i < lista.length; i++){ System.out.println(lista[i]+" "); }*/ bubbleSort(lista); //System.out.println(lista[i]+" "); //skriv ut sorterad array for(int i = 0; i < lista.length; i++){ System.out.println(lista[i]+" "); } } //bubbelsortering public static void bubbleSort(double data[]) { for(int m = data.length-1; m > 0; m--) { for(int n = 0; n < m; n++) { if(data[n] > data[n+1]) { double temp = data[n]; data[n] = data[n+1]; data[n+1] = temp; } } } } //https://www.youtube.com/watch?v=RqfWvIsYmsc }
public class sohel{ public static void main(String args[]){ String a="NASA HACKED"; System.out.println(a); } }
import java.util.Scanner; import java.lang.Math; class Rsa{ static Scanner scan; static int E; static int SI; static int N; static int D; public static void main(String[] args){ scan = new Scanner(System.in); System.out.println("Enter two co prime numbers"); int p = scan.nextInt(); int q = scan.nextInt(); Rsa obj = new Rsa(); obj.calculate(p,q); String message = obj.getMessage(); System.out.println("message: " + message); int intMessage = Integer.parseInt(message); System.out.println("Integer message : " + intMessage); System.out.println((Math.pow(intMessage,E))); double encRes = (Math.pow(intMessage,E)) % N; System.out.println(encRes); } void calculate(int p, int q){ scan = new Scanner(System.in); N = p * q; System.out.println("N : " + N); SI = (p-1)*(q-1); System.out.println("SI : " + SI); System.out.println("Choose a number E where: 1 < E < SI"); E = scan.nextInt(); System.out.printf("public key is : {%d , %d }\n",E,N); D = modInverse(E,SI); System.out.printf("private key is : {%d , %d }\n",D,N); } int modInverse(int E,int SI){ E = E % SI; for(int i = 1; i < SI ;i++){ if((E * i) % SI == 1){ return i; } } return 1; } String getMessage(){ System.out.println("Enter your message"); scan.nextLine(); String message = scan.nextLine(); int readMsg; String buildMsg=""; message = message.toLowerCase(); for(int i=0;i<message.length();i++){ readMsg = (message.charAt(i) - 97) % 26; buildMsg += readMsg; } return buildMsg; } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more