Answer:
Use the command "sensible-browser" I could be wrong I have not used linux in some time.
Explanation:
What is the output of the first and second print statements?
import java.util.ArrayList;
public class addExample
{
public static void main(String[] args) {
ArrayList num1 = new ArrayList ();
ArrayList num2 = new ArrayList ();
num1.add(2);
num1.add(4);
num2.add(10);
num2.add(20);
System.out.println(num1.get(0)+1);
System.out.println(num1.get(1)+ num2.get(0));
}
}
The output of the first print statement is (blank)
and the output of the second statement is (blank).
Answer:
The answer to this question is given below in the explanation section.
Explanation:
When you will run the given code of java in this question. You will get an error and nothing will get printed in the response of the result. Because, in Java, you can't add the two array objects. The reason behind it, java does not support operator overloading. You cannot use the plus operator to add two arrays in Java . It will give you the compile-time error.
There is a method to add two arrays in the Java program is to iterate over them and add individual elements and store them into a new array. This also becomes complex, if you having arrays of different sizes. To go through this method, you have to build a method that will through an illegal exception in case of a mismatch in the sizes of the arrays.
As in the given code, when you execute the first print statement:
System.out.println(num1.get(0)+1);
It will produce error because first type is object and second is int. So, you cannot add object and int value.
When you will execute the given second print statement:
System.out.println(num1.get(1)+ num2.get(0));
it will also produce error, because you cannot add object in Java using + binary operator because in this statement first and second type are both objects.
Write a program that takes paragraph from the user and prints all unique words in that paragraph in c++
Answer:
We strongly recommend you to minimize your browser and try this yourself first
The idea is to use map in STL to keep track of words already occurred.
// C++ program to print unique words in a string
#include <bits/stdc++.h>
using namespace std;
// Prints unique words in a file
void printUniquedWords(char filename[])
{
// Open a file stream
fstream fs(filename);
// Create a map to store count of all words
map<string, int> mp;
// Keep reading words while there are words to read
string word;
while (fs >> word)
{
// If this is first occurrence of word
if (!mp.count(word))
mp.insert(make_pair(word, 1));
else
mp[word]++;
}
fs.close();
// Traverse map and print all words whose count
//is 1
for (map<string, int> :: iterator p = mp.begin();
p != mp.end(); p++)
{
if (p->second == 1)
cout << p->first << endl;
}
}
// Driver program
int main()
{
// Create a file for testing and write something in it
char filename[] = "test.txt";
ofstream fs(filename, ios::trunc);
fs << "geeks for geeks quiz code geeks practice for qa";
fs.close();
printUniquedWords(filename);
return 0;
}
Output:
code practice qa quiz
Thanks to Utkarsh for suggesting above code.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
Explanation:
please mark me as brainliest thank you merry Christmas
which platforms they thinks is better to use for sharing their content,ideas,and stories?
social networking site ? Blogging site?