-
-
Save jookyboi/4342544 to your computer and use it in GitHub Desktop.
Some java files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Hello, Ruby".index "Ruby" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Hello, world" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10.times { puts "Jim" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.upto(10) { |i| puts "This is sentence number #{i}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hhh