Answer:
Following are the code to the given question:
#include<iostream>//including the header file
using namespace std;
int count_Characters(char ch, string s)//defining a method count_Characters that holds two variable as a parameter
{
int c=0,i;//defining integer variable
for(i=0;i<s.size();i++)//using for loop to check value
{
if(s[i]==ch)//use if block to check string and char value
{
c=c+1;//incrementing c value
}
}
return c;//return c value
}
int main() //defining main method
{
char ch;//defining char variable
cin>>ch;//input char value
string s;//defining string variable
cin>>s;//input string value
cout<<count_Characters(ch,s);//calling method count_Characters
return 0;
}
Output:
n Nobody
0
n Monday
1
Explanation:
In this code, a method "count_Characters" is declared that accepts one sting and one char variable as a parameter "s, ch", and inside the method a two integer variable and for loop is declared that uses the if block to match string and char value and increments the c variable value.
In the main method two-variable "s, ch" is declared that inputs the value from the user-end and pass the value into the method, and prints its values.
package brainly;
import java.util.*;
/**
*
* @author CotrinaAlejandra
*/
public class Brainly {
/*Provide the java code, including a comment with your name, course code and date.
Name:
Course:
Date: */
public static void main(String[] args) {
// TODO code application logic here
int number;
Scanner sc = new Scanner(System.in);
System.out.print("Write a four digit number: ");
number=sc.nextInt();
String newLine= String.valueOf(number);
System.out.println(newLine.charAt(0)+" "+newLine.charAt(1)+" "+newLine.charAt(2)+" "+newLine.charAt(3));
}
}
Answer:
Since Python is a scripting language, here is code in python.
#prompt user to give check
amount=float(input("Please Enter the check:"))
#prompt user to give service
service=input("Please Enter the service (good, fair or poor):")
# calculate tip on the basis of service
if service =="good":
tip=amount*0.2
elif service=="fair":
tip=amount*0.15
elif service=="poor":
tip=amount*0.05
#calculate total
total=amount+tip
#print tip
print("tip is equal to : {} ".format(tip))
#print total
print("total of the check is : {} ".format(total))
Explanation:
Prompt user to give check and service input.After taking the input from user, based on the service tip will be calculated. if service is "good" then tip will be 20% of the check, tip will be 15% if service is "fair" and tip will be 5% if service is "poor".
Output:
Please Enter the check:125
Please Enter the service (good, fair or poor):good
tip is equal to : 25.0
total of the check is : 150.0
Answer:
Written in C++
#include<iostream>
using namespace std;
int main()
{
int N;
cout<<"Length of Array: ";
cin>>N;
int A[N], B[N];
for(int i =0;i<N;i++) {
cin>>A[i];
}
for(int i =0;i<N;i++) {
B[i] = A[i];
}
for(int i =0;i<N;i++) {
cout<<B[i]<<" ";
}
return 0;
}
Explanation:
This line declares the length of the Array; N
int N;
This line prompts user for length of array
cout<<"Length of Array: ";
This line gets user input for length of array
cin>>N;
This line declares array A and B
int A[N], B[N];
The following iteration gets input for Array A
for(int i =0;i<N;i++) {
cin>>A[i];
}
The following iteration gets copies element of Array A to Array B
for(int i =0;i<N;i++) {
B[i] = A[i];
}
The following iteration prints elements of Array B
for(int i =0;i<N;i++) {
cout<<B[i]<<" ";
}
Answer:
adaddsad
Explanation:
Answer: Exception
Explanation: A throw statement is a statement that whenever it gets executed ,it stops the flow of the execution immediately. The throw statement has a throw keyword for stopping of the execution which is denoted as the exception. A checked or unchecked exception can only be thrown. The compiler of a program has the function of giving warning if there are chances of exception.
Answer:
public class Main
{
public static void printString(String strText, int intNumber) {
for(int i=0; i<intNumber; i++){
System.out.println(strText);
}
}
public static void main(String[] args) {
printString("Brainly", 3);
}
}
Explanation:
- Define a function called printString that takes two parameters - a String and an int. Since the function will print out the given String, it's type will be void.
- Use for loop to iterate according to the given number and print the given string
- In the main, call the printString function with some parameters.
// Class declaration
public class Printer {
// Define the function and call it printMany
// The return type is void since it doesn't necessarily return any value.
// It just prints to the console.
// It takes two arguments strText of type String and
// intNumber of type int.
public static void printMany(String strText, int intNumber){
// Initialize the loop counter i to 1;
int i = 1;
//Create a while loop that goes
// from i = 1 to i = intNumber.
// Where intNumber is the number of times the string strText
// will be printed.
while(i <= intNumber) {
// At each of the cycle of the loop;
// print out the string strText
// and increment the value of the loop counter by 1
System.out.println(strText);
i++;
} // End of while loop
} // End of method, printMany, declaration
// Write the main method to call the printMany function
public static void main(String[] args) {
// Call the printMany function by supplying sample arguments;
// In this case, strText has been given a value of "Omobowale"
// And intNumber has been given a value of 4
// Therefore, "Omobowale" will be printed 4 times.
printMany("Omobowale", 4);
} // End of main method
} // End of class declaration
When the program above is run, the following will be the output;
----------------------------------------------------
Omobowale
Omobowale
Omobowale
Omobowale
-------------------------------------------------------
Comments:
* The above code has been written in Java
* The code contains comments explaining every part of the code. Kindly go through the comments.
The whole code without comments is re-written as follows;
public class Printer {
public static void printMany(String strText, int intNumber){
int i = 1;
while(i <= intNumber){
System.out.println(strText);
i++;
}
}
public static void main(String[] args) {
printMany("Omobowale", 4);
}
}