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...
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]; ...
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()...
Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...
Java Assignment Calculator with methods. My code appears below what I need to correct. What I need to correct is if the user attempts to divide a number by 0, the divide() method is supposed to return Double.NaN, but your divide() method doesn't do this. Instead it does this: public static double divide(double operand1, double operand2) { return operand1 / operand2; } The random method is supposed to return a double within a lower limit and...
I need help on creating a while loop for my Java assignment. I am tasked to create a guessing game with numbers 1-10. I am stuck on creating a code where in I have to ask the user if they want to play again. This is the code I have: package journal3c; import java.util.Scanner; import java.util.Random; public class Journal3C { public static void main(String[] args) { Scanner in = new Scanner(System.in); Random rnd = new Random(); System.out.println("Guess a number between...