repl.it

    034 - Big Number Program (From Decoding)

    034 - Big Number Program (From Decoding)

    You are given two inputs: int num1; int num2; You can assume that the following: num2 > num1 ==> TRUE You are to write a program that will print out all the ODD numbers in between num1 and num2 inclusive. Your output should all be on one line, separated by spaces. Sample input/output: #1: 3 #2: 11 3 5 7 9 11 #1: 4 #2: 20 5 7 9 11 13 15 17 19 #1: -2 #2: 6 -1 1 3 5 Solution 1 2 3 4 5 6 7 8 9 10 11..

    033 - For Loop Challenge 2 (optional)

    033 - For Loop Challenge 2 (optional)

    Write code that will take in a String input and check to see if it is a palindrome or not. A palindrome means that the characters are the same forwards and backwards, ignoring spaces. Examples of palindromes: racecar was it a car or a cat I saw never odd or even rats live on no evil star Your check should be case insensitive too. For example, "Bob" is a palindrome, despite the first B being capi..

    032 - For Loop Challenge 1 (optional)

    032 - For Loop Challenge 1 (optional)

    The fibonacci sequence is a sequence of numbers in which the next number is the sum of the previous two numbers. The first two numbers of the fibonacci sequence are 0, 1. The first 8 numbers of the fibonacci sequence are 0, 1, 1, 2, 3, 5, 8, 13 Write some code to print out the first X numbers of the fibonacci sequence. Your output should be on one line, with each number separated by a space. You..

    031 - Further For Loop Practice 7 (mIxEd CaSe)

    031 - Further For Loop Practice 7 (mIxEd CaSe)

    Given the following inputs: String s; Write a for loop that will print out the string in alternating cases, with the first letter being lowercase. Keep in mind the following String methods: str.toUpperCase(); //make it uppercase str.toLowerCase(); //make it lowercase DO NOT USE .charAt()! .charAt returns a character, and you need a string in order to make it upper/lowercase. To get a letter at a..

    030 - Further For Loop Practice 6 (reverse string)

    030 - Further For Loop Practice 6 (reverse string)

    Given the following inputs: String s; Write a for loop that will print out the reverse of the string. Sample input/outputs: In: manhattan out: nattahnam In: processor out: rossecorp In: racecar out: racecar Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import java.util.Scanner; class Bakjoon { public static void main(String[] args) { Scanner inp = new Scanner(System.in); System.out.print("In:"); Str..

    029 - Further For Loop Practice 5 (printing characters)

    029 - Further For Loop Practice 5 (printing characters)

    Given the following inputs: String s; Write a for loop that will print out each letter of the string s, separated by spaces, on the same line. Sample input/outputs: In: hello out: h e l l o In: covert out: c o v e r t In: blasphemy out: b l a s p h e m y Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import java.util.Scanner; class Bakjoon { public static void main(String[] args) { Scanner inp = new ..

    028 - Further For Loop Practice 4 (repeating X times)

    028 - Further For Loop Practice 4 (repeating X times)

    Given the following inputs: int x; Write a for loop that will print out "AP CS A" x number of times, new line per print. Sample input/outputs: In: 3 AP CS A AP CS A AP CS A In: 5 AP CS A AP CS A AP CS A AP CS A AP CS A In: 1 AP CS A Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import java.util.Scanner; class Bakjoon { public static void main(String[] args) { Scanner inp = new Scanner(System.in); Sy..

    025 - Further For Loop Practice 1 (ascending)

    025 - Further For Loop Practice 1 (ascending)

    Given the following inputs: int x; Write a for loop that will print out a series of numbers starting at 0 and ending at the x, exclusive. Sample input/outputs: In: 3 out: 0 1 2 In: 8 out: 0 1 2 3 4 5 6 7 In: 5 out: 0 1 2 3 4 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 import java.util.*; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); System.out.print..

    024 - For Loop 6 (optional)

    024 - For Loop 6 (optional)

    Using a for loop, determine whether the integer variable max is prime or not. If the number is prime, print out "prime". If it's not, print out "not prime". Keep in mind that 1 is NOT a prime number. You can use the following to find the square root of a number (you may or may not use this): Math.sqrt(num) Sample input/outputs: In: 100 out: not prime In: 17 out: prime In: 9 out: not prime In: 1 ..

    021 - For Loops 3

    021 - For Loops 3

    Write a for loop that will loop through every character of a word and print out each character, each on a separate line Sample inputs/outputs: In: hello h e l l o 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 import java.util.Scanner; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); System.out.print("In:"); String word = inp.nextLine(); //write your code below..

    020 - For Loops 2

    020 - For Loops 2

    Write a for loop that will print out the numbers starting at 1 and ending at twice the end number exclusive. Each number should be on the same line, separated by a space. Sample inputs/outputs: In: 5 0 1 2 3 4 5 6 7 8 9 In: 10 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 In: -5 (no output) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import java.util.Scanner; class Main { public static void..

    019 - For Loops 1

    019 - For Loops 1

    Inputs: int end; Write a for loop that will print out the numbers starting at 1 and ending at the input inclusive. The numbers printed should all be on the same line separated by a space. Sample inputs/outputs: In: 5 1 2 3 4 5 In: 10 1 2 3 4 5 6 7 8 9 10 In: -5 (no output) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 import java.util.Scanner; class Main { public static void main(String[] args) {..

    018 - Conditional Statement Practice 4

    018 - Conditional Statement Practice 4

    For you to do: Given a string variable "word", do the following tests If the word ends in "y", print "-ies" If the word ends in "ey", print "-eys" If the word ends in "ife", print "-ives" If none of the above is true, print "-s" No more than one should be printed. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 import java.util.*; class Main { public static void ..

    017 - Conditional Statement Practice 3

    017 - Conditional Statement Practice 3

    The variable "name" holds a String user input Write a conditional statement starting on line 9 that does the following: If name is equal to "Chen", print "teacher" For any other input, print "student" Examples: In: Chen teacher In: Faa student 1 2 3 4 5 6 7 8 9 10 11 12 13 import java.util.*; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); System.out.p..

    016 - Conditional Statement Practice 2

    016 - Conditional Statement Practice 2

    The variable "num" holds an integer user input Write a conditional statement starting on line 9 that does the following: If num is even (divisible by 2), print "__ is even" If num is odd, print "__ is odd" Examples: In: 23 23 is odd In: 36 36 is even 1 2 3 4 5 6 7 8 9 10 11 12 import java.util.*; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); System.o..

    015 - Conditional Statement Practice 1

    015 - Conditional Statement Practice 1

    The variable "num" holds an integer user input Write a conditional statement starting on line 9 that does the following: If num is positive, print "__ is positive" If num is negative, print "__ is negative" Examples: In: 5 5 is positive In: -2 -2 is negative In: 0 (no output for zero) import java.util.*; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); ..

    011 - String Methods Practice 2

    011 - String Methods Practice 2

    Given three variables: String str int start int end Print out the following string: The substring of (str) from (start) to (end) is (substring from start to end, inclusive) Sample output: In: lolwut Start: 2 End: 4 The substring of lolwut from 2 to 4 inclusive is lwu PLEASE NOTE that we are counting the end index in our output! lolwut 012345 import java.util.Scanner; class Main { public static v..

    010 - String Methods Practice 1

    010 - String Methods Practice 1

    Given a String (already declared for you as str), do the following: Print out the following: "The first 3 letters of ___ is ___" For example, if the input is "banana", your output should be "The first 3 letters of banana is ban" import java.util.Scanner; class Main { public static void main(String[] args) { Scanner inp = new Scanner(System.in); System.out.print("in:"); String str = inp.nextLine(..

    009 - String Methods - substring

    009 - String Methods - substring

    For you to do: (all output should be one per line) On line 6, write a print statement that prints out a substring of str starting at index 5 and going to the end On line 7, write a print statement that prints out a substring of str starting at index 7 and ending at index 10 On line 10, fill in the () in substring so that it prints "harambe" On line 11, fill in the () in substring so that it prin..

    008 - String Methods - indexOf

    008 - String Methods - indexOf

    For you to do: (the output should be one per line) Print out the position of the first occurrence of "c" Print out the position of the first occurrence of " " Print out the position of the first occurrence of the variable target1 Print out the position of the first occurrence of the variable target2 class Main { public static void main(String[] args) { String str = "abracadabra alakazam"; String..