Answer:
import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
System.out.print("Input a word: ");
String userinput = input.nextLine();
for(int i =0;i<userinput.length();i+=2) {
System.out.print(userinput.charAt(i));
}
}
}
Explanation:
This line prompts user for input
System.out.print("Input a word: ");
This declares a string variable named userinput and also gets input from the user
String userinput = input.nextLine();
The following iterates through every other character of userinput from the first using iteration variable i and i is incremented by 2
for(int i =0;i<userinput.length();i+=2) {
This prints characters at i-th position
System.out.print(userinput.charAt(i));
Answer: money
Explanation: money is life and the air is fat is full of fart
Answer:
Option c is the correct answer for the above question.
Explanation:
- The array is used to holds multiple variables and the assignment operator can assign only a single variable at a time. So if a user wants to assign the whole array value into other array value then he needs to follow the loop.
- The loop iteration moves on equal to the size of the array. It is because the array value moves into another array in one by one. It means the single value can move in a single time. So the moving processor from one array to another array takes n times if the first array size is n.
- The above question asked about the processor to move the element from one array to another and the processor is a loop because the loop can execute a single statement into n times. So the C option is correct while the other is not because--
- Option 'a' states about one assignment operator which is used for the one value only.
- Option b states about the equality operator which is used to compare two values at a time.
- Option d states any of these but only option c is the correct answer.
- Option 'e' states none of these but option c is the correct.