Question

string strings = ""; for (int i = 0; i <= str.length() -1; i++) ( system.out.println(str.charAt(i)...

string strings = "";
for (int i = 0; i <= str.length() -1; i++)
(
system.out.println(str.charAt(i) + "-");
(
)

what output is generated by this

what output is generated?

Homework Answers

Answer #1

According to the above code,

NO OUTPUT WILL BE GENERATED

Because, you have initialized an empty string with name strings and you are trying to print the characters of str.charAt(i), in which str is not initialized.

I will write a simple code which is executable and get you understand.

Code:

  • String strings = "student";
    for (int i = 0; i <= strings.length() -1; i++)
    {
                 System.out.println(strings.charAt(i) + "-");
    }
  • OUTPUT is like below
    • s-
    • t-
    • u-
    • d-
    • e-
    • n-
    • t-

I hope the above code, information and explanation will help you out to understand!

Please comment if you have any queries/errors!

Thank you!

Know the answer?
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
Similar Questions
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length();...
import java.util.Scanner; public class FindMinLength { public static int minLength(String[] array) { int minLength = array[0].length(); for (int i = 0; i < array.length; i++) { if (array[i].length() < minLength) minLength = array[i].length(); } return minLength; } public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] strings = new String[50]; for (int i = 0; i < strings.length; i++) { System.out.print("Enter string " + (i + 1) + ": "); strings[i] = in.nextLine(); } System.out.println("Length of smallest...
Analyze this code and run it, if there are any issues note them and fix them,...
Analyze this code and run it, if there are any issues note them and fix them, if not give the output and Big O notation runtime: public class PrintBits { public static void printBits(int a) { try { String str = Integer.toBinaryString((Integer) a); for(int i = 0; i < str.length(); i++){ System.out.print (str.charAt(i)); } } catch (ClassCastException e) { throw new RuntimeException ("Argument is not an Integer"); } } public static void main (String[] args){ printBits (-17); System.out.println(); printBits (17);...
This is the java code that I have, but i cannot get the output that I...
This is the java code that I have, but i cannot get the output that I want out of it. i want my output to print the full String Form i stead of just the first letter, and and also print what character is at the specific index instead of leaving it empty. and at the end for Replaced String i want to print both string form one and two with the replaced letters instead if just printing the first...
public class PalindromeChecker { /** * Method that checks if a phrase or word is *...
public class PalindromeChecker { /** * Method that checks if a phrase or word is * a Palindrome * * @param str * Represents a string input * * @return true * True if the string is a Palindrome, * false otherwise */ public static boolean isPalindrome(String str) { if (str == null) { return false; } str = str.toLowerCase(); String temp = ""; for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if ((ch...
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
import java.io.PrintStream; import java.util.Arrays; public class joker { public static int smallest(int[] v1, int[] v2) {...
import java.io.PrintStream; import java.util.Arrays; public class joker { public static int smallest(int[] v1, int[] v2) { return 0; } public static int[] convert1(String str) { return new int[1]; } public static String convert2(int[] v) { return ""; } public static void main(String[] args) { testSmallest(); testConvert(); } public static void testSmallest() { System.out.println("Testing your method smallest(...)"); int[][] testVectors1 = new int[][]{{1, 2, 3}, {1, 2, 3, 4}, {1, 2, 3}, {1, 2, 3}, {2, 3, 4}}; int[][] testVectors2 = new...
void reverse_in_place(string& s){ int last = s.length() -1; for (int i = 0; i <= last/2;...
void reverse_in_place(string& s){ int last = s.length() -1; for (int i = 0; i <= last/2; i++){ char temp = s[i]; //i is initially 0 s[i] = s[last-1]; //swapping first and last character s[last- i] = temp; } } This is a c++ program. convert the same function for array and vectors.
public class Mystery { public static String mystery(String str, int input) { String result = "";...
public class Mystery { public static String mystery(String str, int input) { String result = ""; for (int i = 0; i < str.length() - 1; i++) { if (input == 0) { str = ""; result = str; } if (input == -2) { result = str.substring(2, 4); } if (input == 1) { result = str.substring(0, 1); } if (input == 2) { result = str.substring(0, 2); } if (input == 3) { result = str.substring(2, 3); }...
Complete the following functions in the Queue.java/Queue.h files (ATTACHED BELOW): a. void enqueue(int val) b. int...
Complete the following functions in the Queue.java/Queue.h files (ATTACHED BELOW): a. void enqueue(int val) b. int dequeue() c. int getSize() public class Queue {    private int maxQueueSize, front, rear, currentSize; private int[] queue;    public Queue(int maxQueueSize) { if (maxQueueSize <= 0) System.out.println("Queue size should be a positive integer."); else { this.maxQueueSize = maxQueueSize; front = rear = 0; currentSize = 0; queue = new int[maxQueueSize]; } }    public void enqueue(int val) { // complete this function }...
I am trying to take a string of numbers seperated by a single space and covert...
I am trying to take a string of numbers seperated by a single space and covert them into a string array. I have created the following code but it only works if the numbers are seperated a a comma or something similar to that. Example of what I am trying to achieve: string input = "1 1 1 1 1" turn it into.... int[] x = {1,1,1,1} so that it is printed as... [1, 1, 1, 1]    This is...