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 / IfNumbers.java
Last active May 23, 2017 00:08
If statement comparing numbers
public static void main(String[] args) {
// Variables
Scanner input = new Scanner(System.in);
int age;
// Ask a question and save their answer
System.out.print("Enter your age: ");
age = input.nextInt();
@dhust
dhust / IfStrings.java
Last active May 23, 2017 00:15
If statement comparing Strings
public static void main(String[] args) {
// Variables
Scanner input = new Scanner(System.in);
String name;
// Ask and get the user's answer
System.out.print("Enter your name: ");
name = input.next();
@dhust
dhust / and.java
Last active May 23, 2017 00:20
Operators - && (AND)
public static void main(String[] args) {
int a = 14;
if ( (a > 0) && (a < 10) ) {
System.out.println("a is between 0 and 10.");
}
else if (a >= 10 && a < 20) {
System.out.println("a is between 10 and 20, including 10.");
}