For
027 - Further For Loop Practice 3 (descending)
Given the following inputs: int x; Write a for loop that will print out a series of numbers starting at one less than x and ending at 0. Sample input/outputs: In: 7 out: 6 5 4 3 2 1 0 In: 12 out: 11 10 9 8 7 6 5 4 3 2 1 0 In: 20 out:19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Solution 1 2 3 4 5 6 7 8 9 10 11 12 13 14 import java.util.Scanner; class Main { public static void main(String[] a..
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 ..
022 - For Loops 4
Write a for loop that will print out every other letter in a String, starting with the first letter. These letters should be printed all on one line with no space in between. Sample input/outputs In: hello out:hlo In: so code very wow out:s oevr o 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import java.util.Scanner; class Main { public static void main(String[] args) { Scanner inp = new Scan..
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
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
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) {..