import java.util.Scanner;
public class Main
{
public void object(int w, int x)
{
System.out.println(w*x);
}
public void str(String a)
{
System.out.println(a);
}
public static void main(String[] args) {
System.out.println("Hello
World");
Main o1=new Main();
o1.object(5,3);
Main o2=new Main();
o2.str("hello there");
Main o3=new
Scanner(System.in);
String ol=o3.nextLine();
System.out.println(ol);
}
}import java.util.Scanner;
public class Main
{
public void object(int w, int x)
{
System.out.println(w*x);
}
public void str(String a)
{
System.out.println(a);
}
public static void main(String[] args) {
System.out.println("Hello
World");
Main o1=new Main();
o1.object(5,3);
Main o2=new Main();
o2.str("hello there");
Main o3=new
Scanner(System.in);
String ol=o3.nextLine();
System.out.println(ol);
}
}
output:-
Main.java:26: error: incompatible types: Scanner cannot be converted to Main
Main o3=new Scanner(System.in);
^
Main.java:27: error: cannot find symbol
String ol=o3.nextLine();
^
symbol: method nextLine()
location: variable o3 of type Main
2 errors
Answer:-1 and 2 are correct while 3 is wrong
Read the following codes and select the correct results without compiling and runtime errors. Object ol...
composed the following java code to read a string from a text file but receiving compiling errors. The text file is MyNumData.txt. Included the original java script that generated the output file. Shown also in the required output results after running the java program. I can't seem to search for the string and output the results. Any assistance will be greatly appreciated. import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; public class Main { public static void main(String[] args) { System.out.print("Enter the...
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); } ...
Find the worst case runtime f(n) for the following
algorithms.
Specify the number of operations executed for an input size n,
for the worst case run time as a function of n.
Circle statement(s) and draw a line to the right
side specifying the number of operations.
If statement(s) are a part of an iteration of n, specify the
total number of iterations as a function of n.
Algorithm-01 int sum = 0; int j = 1; while ( <=...
With a Scanner object created as follows, what method do you use to read an int value? Scanner input = new Scanner(System.in); A. input.int(); B. input.nextInt(); C. input.integer(); D. input.nextInteger(); What is the output of the following code? x = 0; if (x > 0) System.out.println("x is greater than 0"); else if (x < 0) System.out.println("x is less than 0"); else System.out.println("x equals 0"); A. x is greater than 0 B. x is less than 0 C. x equals 0...
I'm attempting to convert ch object array to double array public void calculateSalesPrice() { double salePrice[] = new double[ch.length]; int p = 0; for (int i = 0; i < ch.length; i += 3) { p = i + 1; for(int j = 0;j } } error message:items.java:16: error: cannot find symbol for(int j = 0;j ^ symbol: variable length location: class Object items.java:17: error: array required, but Object found salePrice[j] = (double full program import java.io.File; import java.util.Scanner; import...
Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link to the file: CountAndAverageNumbers.javaPreview the document. Make sure you include comments in your code where errors were corrected. If you do not flag each error with a comment, points will be deducted. Upload the corrected .java file here. The output of the corrected file looks like the following: Debug4Output.PNG This program reads an unspecified number of integers, determines how many positive and negative values...
Identify and correct the error in the following codes, and state what type of error you will get? public class Assignmet2{ public static void main(String []args){ int x=2; for(int year=1; year>=0; year--) for (int day=2; day!=3; year++) {if ( x>=1) System.out.println("Yes"); else System.out.println("No"); x--;} }} int[] grade = new int[20]; for(int counter=0; counter<=grade.length; i++) grade[counter]=20;
I'm getting a few errors still under RecipeBox. Would you be able to see what's wrong? Thanks ------------ package recipecollection; import java.util.ArrayList; public class SteppingStone5_RecipeTest { public static void main(String[] args) { ArrayList<String> recipeIngredients = new ArrayList<>(); recipeIngredients.add("Peanut butter"); recipeIngredients.add("Jelly"); recipeIngredients.add("Bread"); SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe("Peanut butter & jelly sandwich", 2, recipeIngredients, 300, 10.0); System.out.println("RECIPE 1"); recipe1.printRecipe(); System.out.println(); recipe1.setRecipeName("Turkey sandwich"); recipe1.setServings(5); recipe1.setTotalRecipeCalories(500); System.out.println(); System.out.println("RECIPE 1 (Modified)"); recipe1.printRecipe(); System.out.println(); System.out.println("RECIPE 2"); SteppingStone5_Recipe recipe2 = SteppingStone5_Recipe.createNewRecipe(); recipe2.printRecipe(); } } ///////////////// package recipecollection;...
In Java, I have created a program which can generate passwords. Currently the program can generate a password through a menu system of which characters to use. To complete the project, I need a system which allows the user to generate another password after the first password is created. I also need a method to check whether or not the password is complex by checking if the generated password has 3 or more character types and then displaying whether or...
Select the correct answer. (1) Which of the following will open a file named MyFile.txt and allow you to read data from it? (a) File file = new File("MyFile.txt"); (b) FileWriter inputFile = new FileWriter(); (c) File file = new File("MyFile.txt"); FileReader inputFile = new FileReader(file); (d) FileWriter inputFile = new FileWriter("MyFile.txt"); (2) How many times will the following do - while loop be executed? int x = 11; do { x...