The document contains 3 Java programs:
1) A program that prints a name 21 times using a for loop.
2) A method that takes an array as a parameter, multiplies all elements, and returns the product. It is tested on an example array.
3) A Student class with name, id, and address attributes. An object is created and its setInfo() and getInfo() methods are called to set and print the student details.
Original Description:
Original Title
Write a Java Program to print Your name a certain amount of time
The document contains 3 Java programs:
1) A program that prints a name 21 times using a for loop.
2) A method that takes an array as a parameter, multiplies all elements, and returns the product. It is tested on an example array.
3) A Student class with name, id, and address attributes. An object is created and its setInfo() and getInfo() methods are called to set and print the student details.
The document contains 3 Java programs:
1) A program that prints a name 21 times using a for loop.
2) A method that takes an array as a parameter, multiplies all elements, and returns the product. It is tested on an example array.
3) A Student class with name, id, and address attributes. An object is created and its setInfo() and getInfo() methods are called to set and print the student details.
Write a Java Program to print Your name a certain amount of time
For example (21 times your name using loop)?
package oopsat2022; public class PrintingName { public static void main(String[] args) { for(int i = 1; i <= 21; i++){ System.out.println("Your Name Here"); } } } Write a Java Method to take an array as an input and multiply all numbers of array and return the answer to the user? For example (arr[] = {2,3,4,6}; mult(arr) => 144 ) package oopsat2022; public class Multiply { static double multiply(double numbers[]){ double total= 1; for (int i = 0; i <numbers.length; i++ ){ total = total* numbers[i]; } return total; } public static void main(String[] args) { double numbers[] = {2,3,4,6}; System.out.println("Your Multiplication result is "+ multiply(numbers)); } } Write a Java Class of Your Own Choice and Create an Object of it and call its Methods? package oopsat2022; public class Student { String name; int id; String address; void setInfo(String name, int id, String add){ this.name = name; this.id = id; this.address = add; } void getInfo(){ System.out.println("Your name is " + this.name); System.out.println("Your id is " + this.id); System.out.println("Your Address is " + this.address); } public static void main(String[] args) { Student israr = new Student(); israr.setInfo("Israr Ahmad", 202123, "Kabul"); israr.getInfo(); } }