jookyboi
12/20/2012 - 2:45 AM

Some java files

Some java files

1.upto(10) { |i| puts "This is sentence number #{i}" }
"Hello, Ruby".index "Ruby"
to_guess = rand(10) + 1
puts "Try to guess a number between 1 and 10."

begin
  print "Enter your guess: "
  guess = gets.to_i
  puts "Too low!" if guess < to_guess
  puts "Too high!" if guess > to_guess
end while guess != to_guess

puts "Correct!"
import java.util.Random;
import java.util.Scanner;

public class GuessNumber {
  public static void main(String[] args) {
    Random generator = new Random();
    int toGuess = generator.nextInt(10) + 1;
    int guess;
    Scanner scanner = new Scanner(System.in);
    try {
      System.out.println("Try to guess a number between 1 and 10.");
      do {
        System.out.print("Enter your guess: ");
        guess = scanner.nextInt();
        if (guess < toGuess) {
          System.out.println("Too low!");
        } else if (guess > toGuess) {
          System.out.println("Too high!");
        }
      } while (guess != toGuess);
      System.out.println("Correct!");
    } finally {
      scanner.close();
    }
  }
}