class Progarm1 { public static void main(String[] args) { int[] a = {1, 2}; q3(a); System.out.println( a[0]+ " class Program2 { public static void main(String[] args) { int[] a = {1, 2}; q3(a[0], a[1]); System.out.println(a[0]+ "+ a[1]);} %3D +a[1]);} static void swap(int[] a) { int t = a[0]: a[0] = a[1]; a[1] = t;} static void q3(int n1, int n2) { int t = nl; nl = n2; n2 = t:}
Q: Exercise (5): Strings A. String Length method public class MyClass { public static void…
A: The length of the string is given by the Java string length() method. It returns the total number of…
Q: JAVA PROGRAMMING Please Help! Look over my code and explain to me what I'm doing wrong. Thank You!…
A: Here, I have to write a java code for the above question. The highlighted one is the modified code.
Q: - CPS150 GaussLab2.java Open with - import java.util.Scanner; * CPS150 GaussLab2.java ** / ★ CPS 150…
A:
Q: public class Test { public static void main(String[] args) { Number x = new Integer (3);…
A: //we are getting the error because X is an Number and new Integer is an integer so we are not able…
Q: public class TwoParams{ public static void twoParams (int x, int y){ System.out.println("First…
A: - We need to simulate the code provided.
Q: 1. Recursive Append On RecursiveAppend.java Write a recursive method appendNTimes that receives two…
A: public static String appendNTimes(String original, int n) { if(n == 0) return original; else…
Q: class Main public static void main(Stringt) args) ( String[] words - ( "Ruby", "C", "Python", "Java"…
A: 1. output for this code is: class hello { public static void main(String[] args) { String[]…
Q: 2. public class Test2 { public static void main(String[] args) { for (int x=1; x < args.length; ++x)…
A: Given: public class Test2 { public static void main(String[] args) { for(int x=1;…
Q: The String class is provided in the Java library. Provide your own Java implementation for the…
A: Have to Implement class with name MyString with the following method toUpperCase substring compare…
Q: What does the following code print out? class Main { public static void main (String[] args) { int…
A: In this question, we have given a java code. We have to find the output of the code. We will run the…
Q: Complete the isPalindrome method to recursively determine whether the parameter str is a palindrome.…
A: Question Complete the isPalindrome: import java.util.*; public class PalindromeDetector{…
Q: public static void main (String [] args) { first: for( int i = 1; i < 5; i++) { second: for(int j =…
A: Flow chart: The flow chart shows the steps as boxes of different types and their order when the…
Q: class class { public static void main(String args[]) { int a =5; int b =10; first: { second: {…
A: Given, Programming Language = JAVA Code: class class { public static void main(String…
Q: Create a method that print values of a given interval in a chain of strings beginning with the first…
A: I have made a change in the definition of node. instead of using data instance variable I have used…
Q: public static void main(String[] args) { System.out.println("Testing section one!"); int [] a = {1,…
A: The answer is given below.
Q: public class Con{ public static void main(String[] args) { int[] ar=(2,5,7,9}; int i-2; final int…
A: Ouput of the java code public class Con{public static void main(String[] args){int[]…
Q: public static void doubleArray(int[] a){ int[] newA - new int[a.length]; for (int i = 0; i <…
A: Time complexity defines the worst case running time of the given program. It is denotes as O() -…
Q: Help with java Please import java.util.*; public class Recursion{ public static void…
A: Java program which take user input and add the user input according to its lenght
Q: public class P3 { public static void main(String[] args) { int[] intArray = new int[10]; for (int i…
A: It basically put value of i into array arrar[i] basically it adds number from 0 to 9…
Q: A palindrome is a string of characters that reads the same from right to left as it does from left…
A: import java.util.Stack;import java.util.Queue;import java.util.LinkedList;import…
Q: public class Main { public static void main(String[] args) { int result = sum(10, 10);…
A: Given Java program
Q: Make the code output sentence starts with a capitalization, and ends with a period. public class…
A: Send your complete code. I will answer. Have a great day.
Q: public class Test { public static void main(String[] args) { int[][] array ={{ 8, 9, 10, 11 }, { 4,…
A: Explanation and logic Here we have two dimensional array which can be represent like this(In matrix…
Q: public static void methodl (int i, int num) { for (int j System.out.print num = 2; 1; j <= i; j++) {…
A: The given code is written in Java.
Q: (Java) Write a program that uses String method regionMatches to compare two strings input by the…
A: The method regionMatches() compares two Strings to see if they are equal. One can match the…
Q: public static void main(String [] args) { int num1 = 5, num2 = 10; swap(num1, num2);…
A: Given: public static void main(String [] args){ int num1 = 5, num2 = 10; swap(num1, num2);…
Q: public class My { public static void main(String [] args) { printAll(args); } public static void…
A: Consider the given code:
Q: The String class is provided in the Java library.Provide your own implementation for the following…
A: Program structure Import class Arrays from the util package in the program. Create a Main class…
Q: public class MyClass { public static void main(String args[]) id(1) id(2) "s26j9876" }; id(0) String…
A: Length of id[0] is 8index of 7 in id[2] is 68+6=14Length of id is 3 So final output is 143
Q: Write a Java program for the following Class Diagram. Document -authors : Stringl date : Date…
A: package database; public class Book{ /* at the very beginning we require to create instance…
Q: A palindrome is a string that is spelled the same way forward and backward. Some examples of palindr…
A: soulution: import java.util.Scanner;public class Palindrome{ public static void main(String[]…
Q: JAVA CODE: class quad{ public static void main(String args[] ){ Quadrilateral quadrilateral = new…
A: Errors that stop the source program from executing due to incorrect syntaxes are known as Compile…
Q: Analyse the following code: public class Test { public static void main(String[] args) {…
A: Required: Analyse the given code:
Q: public class Main5 public static void main(String] args) { int a = 5; int b = 6, float c = alb,…
A: The answer is as follows:-
Q: public class MaxMinAtLeastOneValue public static void main(String[] args) { Scanner in = new Scanner…
A: - We have to code for the java program of min, max and count values.
Q: public class Ex1 { public static void main( String args[] ){ int array[] = { 1, 2, 3, 4, 5 };
A: Code:
Q: public class MyClass { public static void main (String args []) { int x = 1; System.out.println(x) ;…
A: here I written given code with fully understand language with comments that how all value will…
Q: public class Find Errors ( public static void main (String[] args) ( 3 int a = 8; %3D int b = 9.0;…
A: Q: Find errors in the given program
Q: public class Myjava Programs { public static void main(String[] args) { int row, column; row = 1; do…
A: The Flowchart is created using Online Flowchart Tool Below:
Q: ava programming Write two methods in the Java programming language, the first using recursion to…
A: Write two methods in the Java programming language, the first using recursion to find the smallest…
Q: public class Test { } public static void main(String[] args) { int a = 10;…
A: The output of the above code will be
Q: public class Test { } public static void main(String[] args) { String str = "Salom";…
A: S
Q: public class Main { public static void main(String[] args) { System.out.println("Your…
A: Algorithm :- 1 - start 2- read number n 3- call factorial 4- print factorial factorial(number) 1- if…
Q: import javax.swing.JOptionPane; public class Addition { public static void main( String args[] ) {…
A: you are not calculating the sum in your code. you are just assigning the number to sum every time…
Q: Java: Class: MiddleStr Write a method public static String middle(String str) that returns a…
A: public class MiddleStr{ public static void main(String[] args) { System.out.println("Middle element…
Q: public class P2 { public static void main(String[] args) { int[][] a2 = new int[3][3]; for (int i=0;…
A: According to the information given:- We have to compile this code and find out its output.
Q: The String class is provided in the Java library. Provide your own Java implementation for the…
A: Explanation: charAt() The charAt () function of the Java-String class produces the character…
Q: import java.awt.*; public class TestRectangle { public static void main(String[] args) { Rectangle…
A: PROGRAM: //Defining class class Rectangle { //Declaring variables int x; int y;…
Step by step
Solved in 2 steps
- Question 37 public static void main(String[] args) { Dog[] dogs = { new Dog(), new Dog()}; for(int i = 0; i >>"+decision()); } class Counter { private static int count; public static void inc() { count++;} public static int getCount() {return count;} } class Dog extends Counter{ public Dog(){} public void wo(){inc();} } class Cat extends Counter{ public Cat(){} public void me(){inc();} } The Correct answer: Nothing is output O 2 woofs and 5 mews O 2 woofs and 3 mews O 5 woofs and 5 mews Oa) FindMinIterative public int FindMin(int[] arr) { int x = arr[0]; for(int i = 1; i < arr.Length; i++) { if(arr[i]< x) x = arr[i]; } return x; } b) FindMinRecursive public int FindMin(int[] arr, int length) { if(length == 1) return arr[0]; return Math.Min(arr[length - 1], Find(arr, length - 1)); } What is the Big-O for this functions. Could you explain the recurisive more in details ?//Program 1 public class T1_3 { public static void main (String[] args) { int [][] arr = { {7,2,6},{6,3,2} }; for (int row = 1; row < arr.length; row++) { for (int col = 0; col < arr[0].length; col++) { if (arr[row] [col] % 2 == 1) arr[row] [col] = arr[row][col] + 1; else arr[row] [col] = arr[row][col] * 2; } What is the content of arr[][], after Program l is executed? arr[o][0]= arr[0][1]= arr[0][2]= arr[1][0]= arr[1][1]= arr[1][2]=
- Instructions Insurance.java >- Terminal + 1 import java.util.Scanner; sandbox $ 0 2 class Insurance { The Harrison Group Life Insurance company computes public static void main (String args[]) { // Write your code here annual policy premiums based on the age the customer 4 turns in the current calendar year. The premium is } computed by taking the decade of the customer's age, adding 15 to it, and multiplying by 20. 7 public static int calculatePremium(int curr, int birth) { 8 // Write your code here } For example, a 34-year-old would pay $360, which is calculated by adding the decades (3) to 15, and then 10 } 11 multiplying by 20. Write an application that prompts a user for the current year then a birth year. Pass both to a method that calculates and returns the premium amount, and then display the returned amount. An example of the program is shown below: Enter the current year >> 2020 Enter the birth year >> 2001 The premium is $320 Grading Write your Java code in the area on the…C++ A robot is initially located at position (0; 0) in a grid [?5; 5] [?5; 5]. The robot can move randomly in any of the directions: up, down, left, right. The robot can only move one step at a time. For each move, print the direction of the move and the current position of the robot. If the robot makes a circle, which means it moves back to the original place, print "Back to the origin!" to the console and stop the program. If it reaches the boundary of the grid, print \Hit the boundary!" to the console and stop the program. A successful run of your code may look like:Down (0,-1)Down (0,-2)Up (0,-1)Left (-1,-1)Left (-2,-1)Up (-2,0)Left (-3,0)Left (-4,0)Left (-5,0)Hit the boundary! or Left (-1,0)Down (-1,-1)Right (0,-1)Up (0,0)Back to the origin! About: This program is to give you practice using the control ow, the random number generator, and output formatting. You may use <iomanip> to format your output. You may NOT use #include "stdafx.h".T/F A Java main method uses the parameter (String[ ] variable) so that a user can run the program and supply“command-line” parameters. Since the parameter is a String array, however, the user does not have to supply anyparameters.
- public class Program7 { publicstaticvoidmain(String[]args){ int[]numbers=newint[100]; String[]names={"Maria","Aris","Galin","Galena"}; double[]balances=newdouble[]{2,56,12.57,36.57,57.89}; //length System.out.println(numbers.length); System.out.println(names.length); System.out.println(balances.length); //modifying names[3]="Celine Dion"; System.out.println("__________________________"); //looping for(inti=0;i<names.length;i++){ System.out.println(names[i]); } System.out.println("__________________________"); for(Stringname:names){ System.out.println(name); } //modifying array System.out.println("__________________________"); for(inti=0;i<names.length;i++){ names[i]=names[i]+" Annan"; System.out.println(names[i]); } System.out.println("__________________________"); doubletotal=0.0; for(inti=0;i<balances.length;i++){ total+=balances[i]; } System.out.println("Total Balance: "+ total); } } //calculate the average of the total balancemain.cpp:4:17: error: 'string' has not been declared 4 | void KMPSearch(string pat, string txt) main.cpp:4:29: error: string' has not been declared 4 | void KMPSearch(string pat, string txt) Aununun main.cpp:31:25: error: string' has not been declared 31 | void computelPSArray(string pat, int M, int[] lps) main.cpp:31:50: error: expected or . before lps' 31 | void computeLlPSArray(string pat, int M, int[] lps) main.cpp:55:8: error: expected :' before 'static' 55 | public static void Main() main.cpp:61:2: error: expected ;' after class definition 61 | } | main.cpp: In member function 'void GFG::KMPSearch(int, int)': main.cpp:6:15: error: request for member Length' in 'pat', which is of non-class type 'int' 6 | int M = pat.Length; main.cpp:7:15: error: request for member Length' in txt’, which is of non-class type 'int' int N = txt.Length; main.cpp:8:6: warning: structured bindings only available with -std3c++17' or (-std=gnu++17' 8 | int[] lps new int[M];#include <stdio.h> int arrC[10] = {0}; int bSearch(int arr[], int l, int h, int key); int *joinArray(int arrA[], int arrB[]) { int j = 0; if ((arrB[0] + arrB[4]) % 5 == 0) { arrB[0] = 0; arrB[4] = 0; } for (int i = 0; i < 5; i++) { arrC[j++] = arrA[i]; if (arrB[i] == 0 || (bSearch(arrA, 0, 5, arrB[i]) != -1)) { continue; } else arrC[j++] = arrB[i]; } for (int i = 0; i < j; i++) { int temp; for (int k = i + 1; k < j; k++) { if (arrC[i] > arrC[k]) { temp = arrC[i]; arrC[i] = arrC[k]; arrC[k] = temp; } } } for (int i = 0; i < j; i++) { printf("%d ", arrC[i]); } return arrC; } int bSearch(int arr[], int l, int h, int key) { if (h >= l) { int mid = l + (h - l) / 2; if…
- // Application allows user to enter a series of words // and displays them in reverse order import java.util.*; public class DebugEight4 { publicstaticvoidmain(String[] args) { Scanner input =newScanner(System.in); int x =0, y; String array[] =newString[100]; String entry; finalString STOP =XXX; StringBuffer message =new StringBuffer("The words in reverse order are\n"); System.out.println("Enter any word\n" + "Enter + STOP + when you want to stop"); entry = input.next(); while(!(entry.equals(STOP))) { array[x] = entry; ++x; System.out.println("Enter another word\n" + "Enter "+STOP+" when you want to stop"); entry = input.next(); } for(y = x -1; y >0; ++y) { message.append(array[y]); message.append("\n"); } System.out.println(message) }public static String pancakeScramble(String text) This nifty little problem is taken from the excellent Wolfram Challenges problem site where you can also see examples of what the result should be for various arguments. Given a text string, construct a new string by reversing its first two characters, then reversing the first three characters of that, and so on, until the last round where you reverse your entire current string.This problem is an exercise in Java string manipulation. For some mysterious reason, the Java String type does not come with a reverse method. The canonical way to reverse a Java string str is to first convert it to mutable StringBuilder, reverse its contents, and convert the result back to an immutable string, that is,str = new StringBuilder(str).reverse().toString(); Here's the tester it must pass: @Test public void testPancakeScramble() throws IOException {// Explicit test casesassertEquals("", P2J3.pancakeScramble(""));assertEquals("alu",…public static String pancakeScramble(String text) This nifty little problem is taken from the excellent Wolfram Challenges problem site where you can also see examples of what the result should be for various arguments. Given a text string, construct a new string by reversing its first two characters, then reversing the first three characters of that, and so on, until the last round where you reverse your entire current string. This problem is an exercise in Java string manipulation. For some mysterious reason, the Java String type does not come with a reverse method. The canonical way to reverse a Java string str is to first convert it to mutable StringBuilder, reverse its contents, and convert the result back to an immutable string, that is, str = new StringBuilder(str).reverse().tostring(); A bit convoluted, but does what is needed without fuss or muss. Maybe one day the Java strings will come with the reverse method built in, just like the string data types of all sensible…