Question

Question 39 (1 point) Which one of the following statements can be used to get the fifth character from a string str? char c
Question 40 (1 point) What does the following statement sequence print If the user input is 1234 public static void main(Stri
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Output: Output1 is input without space and Output 2 is input with space.

Output 1- enter a number: 123 123456 Output 2- enter a number: 1 2 3 1456

Add a comment
Know the answer?
Add Answer to:
Question 39 (1 point) Which one of the following statements can be used to get the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please make the following code modular. Therefore contained in a package with several classes and not...

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

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

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

  • the question, this is not running it throws an exception would you help me it is...

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

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

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

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

  • Take the following code and add a joption pane to make it eaiser to read. Can...

    Take the following code and add a joption pane to make it eaiser to read. Can anyone tell me whats wrong with my code? It wont compile JAVA. import java.util.Scanner; import java.util.Queue; import java.util.LinkedList; class que { public static void main(String args[]) { int count=0,min=0,hr=0; String a; Scanner inp=new Scanner(System.in); Queue q=new LinkedList<>(); while(count<10) { System.out.println("Enter your name:"); a=inp.nextLine(); q.add(a); count=count+1; min=min+5; if(min>=60) { hr=hr+1; } System.out.println("You are "+count+" in the queue"); System.out.println("Average wait time is "+hr+" hours and "+min+"...

  • Can someone compile this and name the it A4MA5331550.java and compile to make .class file. Will...

    Can someone compile this and name the it A4MA5331550.java and compile to make .class file. Will need to name . class file A4MA5331550 also when done put both files in a zipped folder named A4MA5331550 and email the folder to [email protected] here is the program: import java.util.Scanner; /** * 09/17/2017 * Dakota Mammedaty * MA5331550 * Bubble sorted */ public class MA5331550 { public static void main(String[] args) throws IOException { Sort st =new Sort(); st.getData(); System.out.println("=================Sorting Algorithms================="); System.out.println("1. Bubble...

  • My program will not compile. Recieving an error message: ShoppingBagDemo.java:9: error: cannot find symbol ShoppingBag myBag...

    My program will not compile. Recieving an error message: ShoppingBagDemo.java:9: error: cannot find symbol ShoppingBag myBag = new ShoppingBag(6); ^ symbol: class ShoppingBag location: class ShoppingBagDemo ShoppingBagDemo.java:9: error: cannot find symbol ShoppingBag myBag = new ShoppingBag(6); ^ symbol: class ShoppingBag location: class ShoppingBagDemo 2 errors Here is my code. (Using jGrasp) import java.util.*; class ShoppingBagDemo { public static void main(String[] args) { Scanner sc = new Scanner(System.in); float cost; ShoppingBag myBag = new ShoppingBag(6); System.out.print("Enter count (use 0 to stop):...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT