You are on page 1of 1

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();
}
}

You might also like