|
a. |
for a=1, b=2 |
c. |
for(a=1, b=2) |
|
b. |
for(a=1; b=2) |
d. |
for(a = 1&& b = 2) |
|
a. |
Switch |
c. |
else |
|
b. |
If |
d. |
Break |
|
a. |
Break |
c. |
if |
|
b. |
Switch |
d. |
Case |
customer c=new customer(”ALI”,5)
Which will be the correct way of defining a constructor?
22. All Java application programs must have this method to run.
for(count = 7 ;count> =3; count =count-1)
{
System.out.print(count+” “); }
What is the output?
int X=10;
if ( X >= 10)
{
System.out.print(“ABC”);
}
C.add(4,5,7.8);
Which of the following is the correct form of defining the method?
public class customer
{
public static void main(String [] args)
{
customer st = new customer();
st.print();
}
public static void print() {
int x = 9;
int y, z, calc;
y= 3;
z = 5;
calc = x-y+z;
System.out.println("Product: " + x*y);
System.out.println(calc); }
}
public class welcome
{
public static void main(String [] args)
{
welcome d = new welcome();
d.display();
}
public void display()
{int count;
for (count=6;count<=19;count=count+3)
System.out.println(count);}}
3. .
public class Game1
{
public static void main(String [] args)
{
Game1 s = new Game1();
s.simula();
}
public static void simula() {
int x;
x=3;
do
{
System.out.println(“You are learning Methods!”);
x=x+1;
}while (x <1;}}
Thanks for the question, below are the answers to all the questions. Going forward, please do mention the question number so that I dont need to copy the question.
===================================================================
When creating a for loop, which statement will correctly
initialize more than one variable?
c. for(a=1, b=2)
===================================================================
A method employee() is returning a double value. Which of the
following is the correct way of defining this method?
a. public double employee()
===================================================================
switch
===================================================================
break
===================================================================
If your method is returning values ,what will replace the word
"void" in your method header.
datatype of return value
===================================================================
Which is the correct for form for defining an object?
d. classname objectname=new classname();
===================================================================
public customer(String t, int y);
===================================================================
Question 22
main()
===================================================================
Which of the following is the correct form of defining the
method?
c. public void add(int a,int b,double c)
===================================================================
11 .Write the output?
Output for class customer is below -
Product: 27
11
===================================================================
Output for class welcome is below -
6
9
12
15
18
===================================================================
3. Output for class Game1 is below -
You are learning Methods!
===================================================================
Java Questions When creating a for loop, which statement will correctly initialize more than one variable?...
1) Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...
1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...
12. Predict the output generated at the marked println lines in the following program. The program makes use of the class Employee that is also given. Please enter your answers in the space provided below the code. public class Employee { private String name; private double salary; public Employee(String name, double salary) { this.name = name; this.salary = salary; } public String getName() { return name; } public double getSalary() { return salary; } public void raiseSalary(double percent) { double...
Write the example code to describe overloading and submit here. You need to put comments for your code. You need to add at least one more overloaded method to the example code. public class OverloadingExample { public static void main(String[] args) { OverloadingExample t = new OverloadingExample(); t.methodX(5,9,2.2); t.methodX(5,9,"Hi"); t.methodX(5,9,2); t.methodX(5,9); } public void methodX(int a){ System.out.println("This is the method X with 1 parameters!"); } public void methodX(int a,int b){ System.out.println("This is the method X with 2 parameters!"); } public...
Java help: 1.1) Create a class TA that extends class Student. 1.2) Add a variable to the TA class to represent the course the student is TA'ing. 1.3) Provide a constructor for the class so the code in the PeopleFactory will work as provided. 1.4) Provide a toString() method for the TA class so that TA's will output as shown in the sample code. Provide a class Staff so that you can un-comment the lines of code in the PeopleFactory class that...
please edit my java code perferably on jgrasp version 50.0 , wont complie correctly :( the program is supposed to read from my input file and do the following 1) print out the original data in the file without doing anything to it. 2) an ordered list of all students names (last names) alphabetically and the average GPA of all student togther . 3) freshman list in alphabeticalorder by last name with the average GPA of the freshmen...
2. Write a counter controlled loop to solve the following problems. Each one will involve an array (MinMax.java) Read in 25 ints from the keyboard, and store them in an array. Then, find the maximum and minimum values in such an array, and display them on the screen. public class Array-Assignment { public static void main(String [] args) { int [] x = new int[3]; int [] y = {3, 5, 9, 2}; x[2] = y[3]; ...
In java need help with the TODO sections creating recursive methods public class CountUpDown { /** * countUp - a recursive function that counts up from 1 to n * * @param n the integer value to count up to */ private static void countUp(int n) { // TODO PRELAB // IMPLEMENT THIS RECURSIVE METHOD } /** * countDown - a recursive function that counts down from n to 1 * * @param n the integer value to count down...
Java will be printed 10. can you explain step by step why? public class WhatsPrinted2 { public static void whatHappens(int A[]) { int []B = new int[A.length]; for (int i=0; i<A.length; i++) { B[i]=A[i]*2; } A=B; } public static void main(String args[]) { int A[] = {10,20,30}; whatHappens(A); System.out.println(A[0]); } } will print 10. explain how it's works. Thanks public class WhatsPrinted3 { public static int[] whatHappens(int A[]) { int []B = new int[A.length]; for (int i=0; i<A.length; i++) {...
The method m() of class B overrides the m() method of class A, true or false? class A int i; public void maint i) { this.is } } class B extends A{ public void m(Strings) { 1 Select one: True False For the following code, which statement is correct? public class Test { public static void main(String[] args) { Object al = new AC: Object a2 = new Object(); System.out.println(al); System.out.println(a): } } class A intx @Override public String toString()...