Name: Almosura Paolo R. Dr. Joan P.Lazaro Section: 1me DATE: 03-22-2021 Grade
Name: Almosura Paolo R. Dr. Joan P.Lazaro Section: 1me DATE: 03-22-2021 Grade
MACHINE PROBLEM #3
LOOPS
NAME: ALMOSURA PAOLO R. DR. JOAN P.LAZARO
SECTION: 1ME DATE: 03-22-2021 GRADE:
Problem #1:
Write a program that will display “I will pass NME 2210” 20 times using any loops.
PROGRAM:
package Q;
/**
* @author PAOLO ALMOSURA
*/
public class Q
{
public static void main(String[] args)
{
int number = 1;
while (number <= 20)
{
System.out.println("I will pass NME 2210");
number++;
}
}
}
OUTPUT:
1 | Page
NCP 2210 (Computer Fundamentals and Programming)
Problem #2:
Design a program using Java that will input 10 integers and display its sum and product using
any loops.
PROGRAM:
package Q;
import java.util.Scanner;
/**
* @author PAOLO ALMOSURA
2 | Page
NCP 2210 (Computer Fundamentals and Programming)
*/
public class Q{
public static void main(String[] args)
{
int j, num = 0;
int product = 1, sum = 0;
Scanner keyboard = new Scanner(System.in);
{
System.out.println("Enter 10 numbers : ");
}
for ( j = 0 ;j <10; j++){
num = keyboard.nextInt();
sum += num;
product *= num;
}
System.out.println("The sum of 10 no is : " + sum);
System.out.println("The product of 10 no is : " + product);
}
}
OUTPUT:
3 | Page
NCP 2210 (Computer Fundamentals and Programming)
Problem #3:
Write a program that will input any integer from 1 to 10 and display its factorial using looping.
PROGRAM:
package Q;
import java.util.Scanner;
/**
* @author PAOLO ALMOSURA
*/
public class Q
4 | Page
NCP 2210 (Computer Fundamentals and Programming)
{
public static void main(String[] args)
{
int num, j = 1;
long fact = 1;
System.out.print("Enter any number: ");
Scanner keyboard = new Scanner(System.in);
num = keyboard.nextInt();
OUTPUT:
5 | Page
NCP 2210 (Computer Fundamentals and Programming)
Problem #4:
Write a program that will input N integers and will compute and display its sum and average.
PROGRAM:
package Q;
import java.util.Scanner;
/**
* @author PAOLO ALMOSURA
*/
public class Q
{
public static void main(String[] args)
{
int N, j;
double ave, num = 0, sum = 0;
Scanner keyboard = new Scanner(System.in);
{
System.out.print("Enter N: ");
N = keyboard.nextInt();
System.out.println("Enter " + N + " numbers:");
}
for (j = 0; j < N; j++)
{
num = keyboard.nextInt();
sum += num;
}
ave = sum / N;
System.out.println("The Sum of " + N + " Numbers is : " +
sum);
System.out.println("The Average is : " + ave);
}
}
6 | Page
NCP 2210 (Computer Fundamentals and Programming)
OUTPUT:
Problem #5:
Write a code that will loop by inputting any integer and displays whether the integer is
“POSITIVE” or “NEGATIVE”, and terminate the loop if the integer is equal to zero using any
loops.
PROGRAM:
7 | Page