Skip to content

Instantly share code, notes, and snippets.

public class Cipher {
public static void main(String[] args) {
// TODO Auto-generated method stub
String plaintext = "Oh say can you see";
String ciphertext = "";
String key = "shift";
public class Cipher {
public static void main(String[] args) {
// TODO Auto-generated method stub
String plaintext = "Oh say can you see";
String ciphertext = "";
String key = "shift";
@dhust
dhust / simpleIO.java
Created August 1, 2013 19:25
IO - Simple example
// Ask the person a question they need to respond to
System.out.print("What is your name: ");
// Create a Scanner object to allow input from the user
Scanner inputString = new Scanner(System.in);
// Use the Scanner object to save the user's response, and put it into a String variable
String name = inputString.next();
// Print using their response
@dhust
dhust / complexIO.java
Created August 1, 2013 19:32
IO - Complex example
// Declare variables
Scanner input = new Scanner(System.in);
String favoriteFood;
int numberOfCandyBarsUserCanEat;
// Ask user for favorite food
System.out.print("What is your favorite food? ");
// Store response
favoriteFood = input.next();
@dhust
dhust / print.java
Created August 1, 2013 19:56
print()
// Printing text
System.out.print("Hello class");
// Printing a String
String name = "Dexter";
System.out.print("Hello " + name);
// Printing an integer
int number = 8;
System.out.print("My number is " + number);
@dhust
dhust / printf.java
Created August 1, 2013 19:58
printf()
// Printing text
System.out.printf("Hello class");
// Printing a String
String name = "Dexter";
System.out.printf("Hello %s", name);
// Printing an integer
int number = 8;
System.out.printf("My number is %d", number);
@dhust
dhust / validation.java
Last active December 20, 2015 12:58
IO - validation
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number = 0;
Scanner extraction;
while (number < 1 || number > 10) {
System.out.print("Enter a number (1-10): ");
String line = input.nextLine();
@dhust
dhust / or.java
Created August 1, 2013 20:25
Operators - || (OR)
public static void main(String[] args) {
int a = -4;
if ( (a < 0) || (a > 10) ) {
System.out.println("a is less than 0 or greater than 10.");
}
}
@dhust
dhust / pickUpItem.java
Created August 1, 2013 20:28
How to pick up (knowing you have) an item using booleans
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
// Means that I do not have a sword
boolean youHaveASword = false;
String userChoice;
// Does the user pick up the sword
System.out.print("You see a sword lying next to the river. \nWould you like to pick it up? (y or n) ");
@dhust
dhust / doWhile.java
Last active December 20, 2015 12:59
A generic do-while loop
public class DoWhileLoop {
public static void main(String[] args) {
boolean condition = true;
do {
// code that will repeat goes here