0 views

Original Title: Compilation Jiel

Uploaded by Jerico Hercules Mutia

- Assign Prob
- 76301769-Finite-Element-Methods-Lecture-Notes.pdf
- collegegeom-main-1.pdf
- 3DPROJECT
- The Number
- Shapes Google Sketchup Project Revised
- g9 Maths - Perimeter Area Volume
- Karate Tipki6ns
- Reviewer in Math
- Plan Ai²TS 2019 - 20 Class X
- Ts Policesi 2016 CivilprelimsquestionpaperB
- Math Cad
- 2005 MTAP GR5
- Mathletics Booklet - Area Perimeter
- Lab excercise 4.docx
- 2006onlinemathuheduAP BC Version1 Questions 28
- 5 perimeter and areas notes.pdf
- 700000931_Topper_2_110_1_3_Mathematics_question_up201802121128_1518415122_761
- 4th Periodic Test in Math Wtos(1)
- pi

You are on page 1of 7

JAVA PROGRAMMING

(COMPROG 2526)

07:30 - 09:30 AM TTHS P508

Submitted To: Sir Ramel Cabanilla

25. Read a number and calculate and output its factorial.

import java.util.*;

public class Prob25_CAYABYAB {

public static void main(String[] args) {

/* while

System.out.print ("Enter a number: ");

int x = Keyboard.readInt();

int n = 1;

int f = 1;

while (n<=x){

f = f*n;

n++;

System.out.println ( f + "is factorial of the number. ");

}

*/

/* do while

System.out.print ("Enter a number: ");

int x = Keyboard.readInt();

int n = 1;

int f = 1;

do{

f = f*n;

n++;

System.out.println ( f + "is factorial of the number. ");

}while (n<=x);

*/

//for

System.out.print ("Enter a number: ");

int x = Keyboard.readInt();

for (int n = 1, f = 1; n<=x; n++){

f = f*n;

System.out.println ( f + " is factorial of the number. ");

}

}

}

26. Input and print a number (NUM), its reverse by using operators div and mod. If the

last digit is zero, replace it with a one(1) before reversing the number. Output also

the sum of all the digits.

Example 1:

Input: 543267

Output: 762345 (reversed value)

Sum of all digits: 27

Example 2:

Input: 14980 (add 1 to n such that n=14981.)

Output: 18941 (reversed value)

Sum of all digits: 23

30. Calculate and output the volume and area of spheres using the formula:

V = (4PiR3)/3 A = 4PiR2 where R is the radius of the sphere, from 1 to 20.

public static void main(String[] args) {

/*while

System.out.print("Radius\t Volume\t Area\t");

int r = 1;

while(r<=20){

double v = 4*Math.PI*Math.pow(r,3)/3.0;

double a = 4*Math.PI*Math.pow(r,2);

System.out.printf("\n%4d \t%10.2f \t%8.2f", r,v,a);

r++;

}

*/

/* do while

System.out.print("Radius\t Volume\t Area\t");

int r = 1;

do{

double v = 4*Math.PI*Math.pow(r,3)/3.0;

double a = 4*Math.PI*Math.pow(r,2);

System.out.printf("\n%4d \t%10.2f \t%8.2f", r,v,a);

r++;

}while(r<=20);

*/

//for

System.out.print("Radius\t Volume\t Area\t");

for (int r = 1; r<=20; r++){

double v = 4*Math.PI*Math.pow(r,3)/3.0;

double a = 4*Math.PI*Math.pow(r,2);

System.out.printf("\n%4d \t%10.2f \t%8.2f", r,v,a);

}

}

}

31. Using the equation Y=2+4X-X2, compute and output values of Y for values of X from 1

to 20, and in increment of 1.

public static void main(String[] args) {

/*while

System.out.print("x\t y\t");

int x = 1;

while (x<=20){

int y = 2 + (4*x) - (x*x);

System.out.printf("\n%2d \t%8d", x,y);

x++;

}

*/

/* do While

System.out.print("x\t y\t");

int x = 1;

do{

int y = 2 + (4*x) - (x*x);

System.out.printf("\n%2d \t%8d", x,y);

x++;

}while(x<=20);

*/

//for

System.out.print("x\t y\t");

for (int x = 1; x<=20; x++){

int y = 2 + (4*x) - (x*x);

System.out.printf("\n%2d \t%8d", x,y);

}

}

}

32. An object falling from rest in a vacuum falls 16 feet on the first second, 48 feet

on the 2nd second, 80 feet on the third second, 112 feet the 4th second and so on. Output

the distance traveled by the object after 15 seconds.

public static void main(String[] args) {

/* while

System.out.print("Seconds\t Feet\t\n");

int x=1;

int y = 16;

while (x<=15){

System.out.printf("\n%2d \t"+ y,x);

x++;

y = y + 32;

}

*/

/*do While

System.out.print("Seconds\t Feet\t\n");

int x=1;

int y = 16;

do {

System.out.printf("\n%2d \t"+ y,x);

x++;

y = y + 32;

}while (x<=15) ;

*/

//for

System.out.print("Seconds\t Feet\t\n");

for (int x = 1, y=16; x<=15; x++){

System.out.printf("\n%2d \t"+ y,x);

y = y + 32;

}

}

}

S = 1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/N

Output the number of terms required and the value of S before S exceeds 3.1.

Example:

1st term: S = 1;

2nd term: S = 1 + 1/2 = 1.5;

3rd term: S = 1 + 1/2 + 1/3 = 1.8333;

4th term: S = 1 + 1/2 + 1/3 + 1/4 = 2.08333;

5th term: S = 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.2833;

...

nth term: S = ?

public class Prob34_CAYABYAB {

public static void main(String[] args) {

/* while

System.out.print("\tN\t \tS\n");

int n = 1;

double s = 0;

while (s <= 3.01){

s = s + (1.0/n);

System.out.printf("\n%4d %8.4f", n,s);

n++;

}

*/

/* do while

System.out.print("\tN\t \tS\n");

int n = 1;

double s = 0;

do {

s = s + (1.0/n);

System.out.printf("\n%4d %8.4f", n,s);

n++;

}while (s <= 3.01);

*/

//for

System.out.print("\tN\t \tS\n");

int n = 1;

for (double s = 0; s <= 3.01; n++){

s = s + (1.0/n);

System.out.printf("\n%4d \t%8.4f", n,s);

}

}

}

public static void main(String[] args) {

/* while

int x = 1;

while(x<=150){

System.out.print(x + " ");

x= x+3;

}

*/

/* doWhile

int x = 1;

do{

System.out.print(x + " ");

x = x+3;

}while (x<=150);

*/

// for

for (int x= 1; x<=150; x= x+3){

System.out.print(x + " ");

}

}

}

36. Output the set of numbers in the series 1 2 4 7 11 16 … until 211 is reached.

public static void main(String[] args) {

/* while

int x = 1;

int y = 1;

while (x<=211){

x = x + y++;

System.out.print(x + " ");

}

*/

/* doWhile

int x = 1;

int y = 1;

do{

x = x + y++;

System.out.print(x + " ");

}while (x<=211);

*/

for(int x=1, y=1; x<=211; x=x+y++){

System.out.print(x+ " ");

}

}

}

38. A ball is dropped from an initial height of 50 feet. If the ball bounces 2/3 of

the previous height, make a program that will calculate and print the total distance

traveled by the ball after the 10th bounce.

public static void main(String[] args) {

/* while

double h = 50.0;

double d = 50.0;

int b = 1 ;

while (b<=10){

h = (2/3.0) * h ;

d = d + (2*h) ;

System.out.println("@b = " + b + "\tThe

distance travelled by the ball is " + d);

b++;

}

*/

/* do while

double h = 50.0;

double d = 50.0;

int b = 1 ;

do {

h = (2/3.0) * h ;

d = d + (2*h) ;

System.out.println("@b = " + b + "\tThe distance travelled by the ball is " +

d);

b++;

}

while (b<=10);

*/

//for

double h = 50.0;

double d = 50.0;

for (int b = 1 ; b<=10; b++){

h = (2/3.0) * h ;

d = d + (2*h) ;

System.out.println("@b = " + b + "\tThe distance travelled by the ball is " +

d);

}

}

}

- Assign ProbUploaded byHazel Cordano
- 76301769-Finite-Element-Methods-Lecture-Notes.pdfUploaded byalfredsunny
- collegegeom-main-1.pdfUploaded byMalvado Aun Mas Malvado
- 3DPROJECTUploaded byakincaid
- The NumberUploaded byMayyank Garg
- Shapes Google Sketchup Project RevisedUploaded byErin Whitaker
- g9 Maths - Perimeter Area VolumeUploaded byez
- Karate Tipki6nsUploaded byVulebg Vukoic
- Reviewer in MathUploaded byJohn Walter Camino Daison
- Plan Ai²TS 2019 - 20 Class XUploaded byBISWANATH SEN
- Ts Policesi 2016 CivilprelimsquestionpaperBUploaded byNALLANKI RAJA KUMAR
- Math CadUploaded byFabio Luiz
- 2005 MTAP GR5Uploaded byConrad Dela Cruz
- Mathletics Booklet - Area PerimeterUploaded byJaselyn Koay
- Lab excercise 4.docxUploaded byJhen Dangat
- 2006onlinemathuheduAP BC Version1 Questions 28Uploaded byteachopensource
- 5 perimeter and areas notes.pdfUploaded byLeonel L. Pabilona
- 700000931_Topper_2_110_1_3_Mathematics_question_up201802121128_1518415122_761Uploaded byNimmi Nims
- 4th Periodic Test in Math Wtos(1)Uploaded byownlinkscribd
- piUploaded bydissipog1932
- Add Maths IntegrationUploaded bywuooo
- Lesson 1 AS Maths_a.docxUploaded byWuileap
- 2matematika Sistem PlambingUploaded byhendry_thomson1
- error analysis standardsUploaded byapi-434662376
- Geoboard ActivityUploaded bysandeep
- 52_hw1Uploaded byBalqis Yafis
- Harvard MitUploaded byAlisson Costa
- MathUploaded bySujit Sarkar
- Math Prize 2010 SolutionsUploaded byRicky Ricardo
- Graphics Shapes ManualUploaded byShukrutt

- TE040 Account Receivables Test ScriptsUploaded bythulasee
- mid1-AUploaded byBerrak Kibar
- Drug StudyUploaded byBien Estrella
- Introduction of AccountingUploaded byAnup Mathew
- Citizens for Nuclear Free Iran 2015 990Uploaded byeliclifton
- Fairy Queen LibrettoUploaded byP
- Interstitial Lung DiseaseUploaded bysuntikmati
- Bugils Biweekly #45Uploaded byBugilsGroup
- Student Motivation to LearnUploaded byIvette Fernàndez Arce
- MUNDO CHORDS by IV of Spades @ Ultimate-Guitar.comUploaded byJosephVillanueva
- ASSIGNMENT OF SOFTWARE ENGINEERING.docxUploaded byMaryam Asghar
- Colby Songs take 2Uploaded byMike
- MDGs as My Development GoalsUploaded byINFID JAKARTA
- Rhinoceros - Eugene IonescuUploaded bySergio Ramírez
- Cyber-Stalking or Just Plain Talking?: Investigating the Linguistic Properties of Rape-Threat Messages as Compulsive BehavioursUploaded byJonathan Bishop
- IRJET-Ranking Fraud Detection for Mobile ApplicationsUploaded byIRJET Journal
- english diagnostic testUploaded byPOOJA PARIKH
- PooPourri LawsuitUploaded byThe Dallas Morning News
- Physicochemical And Organoleptic Properties Of Some Selected Foods Fried With Melon (Citrullus Lanatus) Seed OilUploaded byIOSRjournal
- Search and Seizure in the Digital WorldUploaded byjformica
- Reva caseUploaded bySameer Juneja
- U.S. Customs Form: CBP Form 349 - Harbor Maintenance Fee Quarterly Summary ReportUploaded byCustoms Forms
- report on online marketingUploaded byTripta Narwara
- PICos18 Tuto UsUploaded bySkorav
- 75_81_engUploaded bymehrdad_so1981
- Cabanting vs BPI Family Savings Bank IncUploaded byPeMa
- Arogyavardhini VatiUploaded byAATHERSKANNANS
- MBB 1 Handout 1 and What About BiotechnologyUploaded byMariah Shanice Basa
- Material ManagementUploaded byprmnair
- Consultation ReportUploaded byarareyna