0% found this document useful (0 votes)
9 views6 pages

Java Programs for Perfect Numbers and More

The document contains 3 Java programs written by Jeremy Ariola for his IT-1 course. The first program checks if a user-input number is a perfect number by calculating the sum of its factors. The second program prints nested numbers from 1 to a user-input integer. The third program generates a multiplication table from 1 to a user-input number, formatting the output appropriately. Sample outputs for each program are requested but screenshots are not provided.

Uploaded by

Jenny Yen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Java Programs for Perfect Numbers and More

The document contains 3 Java programs written by Jeremy Ariola for his IT-1 course. The first program checks if a user-input number is a perfect number by calculating the sum of its factors. The second program prints nested numbers from 1 to a user-input integer. The third program generates a multiplication table from 1 to a user-input number, formatting the output appropriately. Sample outputs for each program are requested but screenshots are not provided.

Uploaded by

Jenny Yen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name: Ariola,Jeremy Date 10/21/2019

Course & Year: IT-1 Section: 1K

Problem 1:[Link]

import [Link];
public class Perfect
{
public static void main(String[] args)
{
int i, numb, sum=0, x=0, sumy=0;
Scanner input = new Scanner([Link]);
[Link]("Please enter any number: ");
numb = [Link]();
if(1<= numb && numb <=1000){
for (i=1; i<numb; i++)
{
if(numb%i==0)
sum=sum+i;
}
if(sum == numb)
{
[Link](numb+" is perfect because the numbers are: ");
for(int factor=1;factor<numb;factor++)
{
x=numb%factor;
if(x==0)
[Link](factor+ " ");

}[Link](" = "+numb+"\n");
}

else{

[Link](numb+ " is not a perfect number because the numbers are: ");
for(int factor=1; factor<numb;factor++)
for(int factor=1; factor<numb;factor++)
{
x=numb%factor;
if(x==0){
[Link](factor+ " ");
sumy=sumy+factor;
}
}[Link](" = "+sumy+"\n");
}
}else
[Link]("1-1000 ONLY!");
}
}

Sample Output:
(Provide the screenshot of the program’s output.)
Problem 2:[Link]

import [Link];
public class NestedValues
{
public static void main(String[] args)
{
Scanner input = new Scanner([Link]);
int integ;
[Link]("Enter an integer: ");
integ = [Link]();
for(int a=1; a<=integ; a++)
{
for(int b=1; b<=a; b++)
{
[Link](b);
}
[Link]("");
}
}
}

Sample Output:
(Provide the screenshot of the program’s output.)
Problem 3: [Link]

import [Link].*;

public class MultiplicationTable


{
public static void main(String args [])
{
Scanner s = new Scanner([Link]);
[Link]("Enter a number: ");
int num = [Link]();

[Link]("\t |\t");
for(int i = 1; i <= num; i++){
if(i == num)
[Link](" "+i);
else{
if(10<=i && i<=99){
[Link](" "+i+"\t");
}
else if(99<i && i<=1000){
[Link](i+"\t");
}
else{
[Link](" "+i+"\t");
}
}
}
[Link]("-----------+");

for(int i = 1; i <= num; i++){


[Link]("--------");
}
[Link]();

for(int i = 1; i <= num; i++){


if(10<=i && i<=99){
[Link]("\t "+i + "|\t");
}
else if(99<i && i<=1000){
else if(99<i && i<=1000){
[Link]("\t"+i + "|\t");
}
else{
[Link]("\t "+i+ "|\t");
}

for(int j = 1; j <= num; j++){


if(j == num)
{
int product = i*j;
if(product>=10 && product<=99){
[Link](" "+product);
}
else if(product>=99 && product <=999){
[Link](product);
}
else{
[Link](" "+product);
}
}
else
{
int product1 = i*j;
if(product1>=10 && product1<=99){
[Link](" "+product1+"\t");
}
else if(product1>=99 && product1 <=999){
[Link](product1+"\t");
}
else{
[Link](" "+product1+"\t");
}
}
}
}

}
}
Sample Output:
(Provide the screenshot of the program’s output.)

You might also like