Java_beginner(Repl.it)

    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..

    007 - String Methods - charAt

    007 - String Methods - charAt

    For you to do: ALL print statements in this exercise should be on one line, no newlines. Print out the character in the 5th index of the String str Print out the character in the 8th index of the String str Print out the character in the 1st index of the String str Print out the index in the i-th index of the String str (i is a variable already declared for you) class Main { public static void m..

    006 - String Methods - Length

    006 - String Methods - Length

    For you to do: Create a String named "name" and assign the value "Timmy" to it Print out the length of the string variable 'name' class Main { public static void main(String[] args) { String name="Timmy"; System.out.println(name.length()); } }

    005 - Creating Variables and Printing 5

    005 - Creating Variables and Printing 5

    Creating Variables and Printing 5 For you to do: Create a String variable called "name" and set it to "Chen" Create an integer variable called "age" and set it to 50 Create an integer variable called "iq" and set it to the value of age (do NOT use ' = 50') Print the value of name Print the value of age without skipping a new line Print the value of iq class Main { public static void main(String[..

    004 - Creating Variables and Printing 4

    004 - Creating Variables and Printing 4

    Creating Variables and Printing 4 Print out the following pattern: * ** *** ## # class Main { public static void main(String[] args) { System.out.println("*"); System.out.println("**"); System.out.println("***"); System.out.println("##"); System.out.println("#"); } }

    003 - Creating Variables and Printing 3

    003 - Creating Variables and Printing 3

    Creating Variables and Printing 3 For you to do: Create a boolean variable called "isTrue" and set it to false Create a double variable called "money" and set it to 99999.99 Print the variable "money" first Then print the variable "isTrue" without skipping to the next line. class Main { public static void main(String[] args) { boolean isTrue=false; double monet=99999.99; System.out.print(monet);..

    002 - Creating Variables and Printing 2

    002 - Creating Variables and Printing 2

    2019/11/26 Creating Variables and Printing 2 For you to do: Create an integer variable on line 4 and set it to the value 21. class Main { public static void main(String[] args) { int age=21; System.out.println(age); } }

    001 - Creating Variables and Printing 1

    001 - Creating Variables and Printing 1

    2019/11/26 Creating Variables and Printing Them For you to do: Create two String variables called firstName and lastName respectively. Assign the String "Bob" to firstName and "Jones" to lastName. Print firstName and lastName, one per line. Each should use a different print statement. import java.util.*; class Main { public static void main(String[] args) { String firstName ="Bob"; String lastNa..