Q39)
str.charAt(int index) returns the character at the specified index in a string.
The string index begins from 0.
To get the fifth character from the string str, we need to
specify
char c=
str.charAt(4);
So in the given options 1st option is correct.
eg:
| a | p | p | l | e | s |
| 0 | 1 | 2 | 3 | 4 | 5 |
Here the 5th character is 'e'. Its index is 4.
Q 40. The correct option is 2nd.
The program reads the input and concatenates 456 at the end of the
input string.
Note: If you give space while giving input, it reads till space and concatenates 456. (see output2)
The complete program with output is shown below:
![2 import java.util.Scanner; 3 class Main 4-{ public static void main(String[] args) Scanner in =new Scanner (System.in); Syst](http://img.homeworklib.com/questions/6a579fb0-212d-11eb-bd7a-0f125449d9a3.png?x-oss-process=image/resize,w_560)
Output: Output1 is input without space and Output 2 is input with space.

Question 39 (1 point) Which one of the following statements can be used to get the...
Hello, I posted the same question a little bit ago and it was answered correctly however I didn't ask it quite correctly so I wanted to post it again asking what I want correctly. Basically the idea of the assignment the user should be able to enter a single word or sentence and it will output all the vowels in the sentence so for example the sentence "I think therefore I am" should print out {1,3,3,1,0} just once, then it...
Hello, can get some help with simple pseudocode describing the steps for this program below? THUMBS UP always left for help! public class TimeDemo { private static Scanner keyboard; private static String enteredTime; private static Time now; public static void main (String [] args) { keyboard = new Scanner(System.in); char answer = 'Y'; enteredTime = null; String response; while (answer== 'Y') { System.out.print( "Enter a military time using the ##:##...
Please make the following code modular. Therefore contained in a package with several classes and not just one. import java.util.*; public class Q { public static LinkedList<String> dogs = new LinkedList<String> (); public static LinkedList<String> cats = new LinkedList<String> (); public static LinkedList<String> animals = new LinkedList<String> (); public static void enqueueCats(){ System.out.println("Enter name"); Scanner sc=new Scanner(System.in); String name = sc.next(); cats.addLast(name); animals.addLast(name); } ...
Please, modify the code below to use the Switch Statements in Java instead of “if” statements to make the decisions. import java.util.Scanner; public class Area { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter code(C for circle, R for rectangle, S for square): "); char code = in.next().charAt(0); if(code == 'C') { System.out.print("Enter radius: "); double radius = in.nextDouble(); System.out.println("Area of circle is " + (Math.PI * radius * radius)); } else if(code == 'R') {...
Hello, I have a assignment where the user inputs a word and the out will then tell the user how many of the five vowels are in the word so for example if I typed the word hello, it would output {0 1 0 0 0 } since there is only one vowel and that is e which is in the second row, I have most of it done, but I can't seem to figure out how to get the...
I am gettting error saying that I need to initialize variable but I want to get inputs from the user and want to print them out. (using "for" loop) public static void main(String[] args) { String input; int i; Scanner sc = new Scanner(System.in); for (i=1; i < 5; i++) { System.out.print(i+ ". Please enter a name: "); input = sc.nextLine(); } System.out.println("All names are here:" + input); } }
the question, this is not running it throws an exception would you help me it is a java program // why this is not running would you help me public class sample { public static void main(String[] args){ String str[][] = new String[10]['K']; for(int i= 1;i<=10; i++){ for(char j= 'A';j<='J'; j++){ System.out.print(i +" "+ j); str[i][j] = "A"; System.out.print(" "); } System.out.println(); } ...
Java 1. Can you explain it how it will be printed step by step? Thanks!! What is printed by the following? for (int i=1; i<4; i++) { for (char c=’a’; c<=’c’; c++) { if (i%2==0) { i++; System.out.println(i + " " + c); } else { c++; System.out.println(c + " " + i); } } } 2. Is there a compiler error in this code? If so, what is it? If not, what’s printed? Is there a compiler error in...
DEBUGGING. JAVA. Identify the errors in the following. There are no logical errors in this one just syntax issues. //start import java.util.Scanner; public class NumbersDemo { public static void main (String args[]) { Scanner kb = new Scanner(System.in); int num1, num2; System.out.print("Enter an integer >> "); num1 = kb.nextInt(); System.out.print("Enter another integer >> "); num2 = kb.nextDouble(); displayTwiceTheNumber(num1); displayNumberPlusFive(num1); displayNumberSquared(num1) displayTwiceTheNumber(num2); displayNumberPlusFive(num2); displayNumberSquared(num2); } ...
JAVA Can you make this return the first letter of first and last name capitalized? import java.io.File; import java.io.IOException; import java.util.*; public class M1 { public static void main(String[] args) { //scanner input from user Scanner scanner = new Scanner(System.in); // System.out.print("Please enter your full name: "); String fullname = scanner.nextLine(); //creating a for loop to call first and last name separately int i,k=0; String first="",last=""; for(i=0;i<fullname.length();i++) { char j=fullname.charAt(i); if(j==' ') { k=i; break; } first=first+j;...