166 views

Uploaded by Anagha Walimbe

JAva practice questions

JAva practice questions

© All Rights Reserved

- TCS Aspire ILP Web Tech quiz all solutions
- TCS Aspire Quiz and Assignments
- TCS Aspire Basics of Programming Assignment Solutions
- Tcs Aspire Java2
- Quiz
- TCS Aspire
- tcs questions and answers
- TCS ASPIRE Assignments on Database, JAVA, UNIX with solutions
- 1
- Python(aspire)
- Aspire Set of Questions
- Aspire Syllabus
- Make Success Measurable
- Miscellaneous Aspire Stuff
- Aspire Quiz
- Java Tech Lounge
- TCS Aspire- Chapter 4
- TCS ASPIRE RDBMS_2
- Intro to JAVA Assignment 1
- Intro to Java Assignment2

You are on page 1of 5

1. Write a program to find the difference between sum of the squares and the square of the sums

of n numbers? Sum of the square(n) ,square of sum n

import java.util.Scanner;

import java.lang.String;

class sum

{

public static void main(String args[])

{

float s=0,s2=0;int i;

System.out.println(enter n value);

Scanner st=new Scanner(System.in); int n=st.nextInt();

int a[] =new int[n];

for(i=0;i<n;i++)

{a[i]=st.nextInt(); //enter n values

}

for(i=0;i<n;i++)

{

s=s+a[i];

}

float d=(s*s);

for(i=0;i<n;i++)

{s2=s2+((a[i])*(a[i]));}

float f = (d-s2);

System.out.println(f);

System.out.println(difference between sum of the squares and the square of the sums of

+n+numbers is: +f);

}}

2. Develop a program that accepts the area of a square and will calculate its perimeter.

import java.util.Scanner;

import java.lang.*;

class area

{

public static void main(String args[])

{

System.out.println(enter area value);

Scanner st=new Scanner(System.in);

double n=st.nextDouble();

double s=Math.sqrt(n);

double perimeter=4*s;

System.out.println(perimeter);

}

}

3. Develop the program calculateCylinderVolume., which accepts radius of a cylinder's base disk

and its height and computes the volume of the cylinder.

import java.util.Scanner;

import java.lang.*;

class calculateCylinderVolume

{

public static void main(String args[])

{

double v=0;

System.out.println(enter radius value);

Scanner st=new Scanner(System.in); double r=st.nextDouble();

System.out.println(enter height);

double h=st.nextDouble();

double p=Math.PI;

v=p*r*r*h;

System.out.println(Volume of cylinder is: +v);

}

}

4. Utopias tax accountants always use programs that compute income taxes even though the tax

rate is a solid, never-changing 15%. Define the program calculateTax which determines the tax

on the gross pay. Define calculateNetPay that determines the net pay of an employee from the

number of hours worked. Assume an hourly rate of $12.

import java.util.*;

import java.text.*;

public class CalculateTax

{

public static void main (String[] args) {

double trate=0.15;

double hrate=12;

Scanner input=new Scanner(System.in);

System.out.println(Enter Number of Days Worked in a year:);

int days=input.nextInt();

System.out.print(Enter Number of Working hours: );

double hrs=input.nextDouble();

double gpay=days*hrs*hrate;

double tax=gpay*trate;

double netpay=gpay-tax;

System.out.println(Net Pay is: $+netpay);

}

}

5. An old-style movie theater has a simple profit program. Each customer pays $5 per ticket.

Every performance costs the theater $20, plus $.50 per attendee. Develop the program

calculateTotalProfit that consumes the number of attendees (of a show) and calculates how much

income the show earns.

import java.io.*;

import java.util.Scanner;

class calculateTotalProfit

{

public static void main(String args[]) throws IOException

{

Scanner s=new Scanner(System.in);

System.out.println(Enter the number of attendes for show : );

int a=s.nextInt();

double percost = 20 ;

double attendecost =0.5;

double profit = (5*a)-(a*attendecost+20);

System.out.println(The profit for the show is : $+profit);

}

}

6. Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk

and its height and computes surface area of the cylinder.

import java.io.*;

import java.util.Scanner;

import java.lang.*;

class calculateCylinderArea

{

public static void main(String args[]) throws IOException

{

Scanner s=new Scanner(System.in);

System.out.println(Enter the base radius of cylinder(in m): );

double r=s.nextDouble();

System.out.println(Enter the height of cylinder(in m) : );

double h=s.nextDouble() ;

double pi=Math.PI;

double surfacearea=(2*pi*r*(r+h));

System.out.println(The calculated surface area is: +surfacearea+ sq m);

}

}

7. Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an

open cylinder. The program accpets three values: the pipes inner radius, its length, and the

thickness of its wall.

import java.io.*;

import java.util.Scanner;

import java.lang.*;

class calculatePipeArea

{

public static void main(String args[]) throws IOException

{

Scanner s=new Scanner(System.in);

System.out.println(Enter the inner radius of pipe(in m): );

double r=s.nextDouble();

System.out.println(Enter the length of pipe(in m) : );

double l=s.nextDouble() ;

System.out.println(Enter the thickness of pipe(in m) : );

double t=s.nextDouble() ;

double pi=Math.PI;

double surfacearea=(2*pi*(r+t)*l);

System.out.println(The calculated surface area is: +surfacearea+ sq m);

}

}

8. Develop the program calculateHeight, which computes the height that a rocket reaches in a

given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g t in t

time units and a height of 1/2 * v * t where v is the speed at t.

import java.util.Scanner;

public class calculateHeight {

public static void main(String[] args) {

System.out.println(Enter the time in seconds : );

Scanner s=new Scanner(System.in);

double time=s.nextDouble();

double acc;

double g=9.8;

acc=g;

double vel=acc*time;

double h=(vel*time)/2;

System.out.println(Height reached by the rocket (in km) is : +(h/1000));

}

}

9. Develop a program that computes the distance a boat travels across a river, given the width of

the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time,

and the Pythagorean Theorem is c2 = a2 + b2.

import java.util.Scanner;

public class Distance{

public static void main(String[] args)

{

Scanner s= new Scanner(System.in);

System.out.println(Enter the width of the river (in m) : );

double width=s.nextDouble();

System.out.println(Enter speed of river (in m/s) : );

double rspeed=s.nextDouble();

System.out.println(Enter speed of the boat(in m/s) : );

double bspeed=s.nextDouble();

double time=width/bspeed; //time to travel to other bank by the boat

double d=time*rspeed; //distance travelled down stream

double totald=Math.sqrt((width*width)+(d*d));

System.out.println(The distance travelled by boat(in m): +totald);

}

}

10. Develop a program that accepts an initial amount of money (called the principal), a simple

annual interest rate, and a number of months will compute the balance at the end of that time.

Assume that no additional deposits or withdrawals are made and that a month is 1/12 of a year.

Total interest is the product of the principal, the annual interest rate expressed as a decimal, and

the number of years.

import java.util.Scanner;

public class calculateBalance {

public static void main(String[] args)

{

Scanner s=new Scanner(System.in);

System.out.println(Enter the principal amount : );

double p=s.nextDouble();

System.out.println(Enter the annual interest rate in percentage: );

double ir=s.nextDouble();

System.out.println(Enter the number of months : );

double m=s.nextDouble();

double ad=p*(m/12)*(ir/100);

double finalbal=p+ad;

System.out.print(final balance will be +finalbal);

}

}

- TCS Aspire ILP Web Tech quiz all solutionsUploaded byashcool100
- TCS Aspire Quiz and AssignmentsUploaded bySindhu Smiley
- TCS Aspire Basics of Programming Assignment SolutionsUploaded bymeenu_sharma06
- Tcs Aspire Java2Uploaded byAnagha Walimbe
- QuizUploaded bybhanumathy91
- TCS AspireUploaded bydurkaganes
- tcs questions and answersUploaded byRaj Bhatia
- TCS ASPIRE Assignments on Database, JAVA, UNIX with solutionsUploaded bymeenu_sharma06
- 1Uploaded byDiptiJha
- Python(aspire)Uploaded byAvinash Kharche
- Aspire Set of QuestionsUploaded byGORAK
- Aspire SyllabusUploaded byAbhilash Vvg
- Make Success MeasurableUploaded bySalah Elbakkoush
- Miscellaneous Aspire StuffUploaded byMaanas Khurana
- Aspire QuizUploaded bySushmitha Achanta
- Java Tech LoungeUploaded byAnkur Bhatnagar
- TCS Aspire- Chapter 4Uploaded byhimanshu_garg93
- TCS ASPIRE RDBMS_2Uploaded byshri harsha
- Intro to JAVA Assignment 1Uploaded bymeenu_sharma06
- Intro to Java Assignment2Uploaded bymeenu_sharma06
- pat testUploaded byNiranjani Prasad
- Chapter3 (1)Uploaded byBishwadeep Das
- DBMSUploaded byAnanya Sinha
- TCS QuestionsUploaded byanon-92459
- know ur tcsUploaded byAakash Mazumder
- 1xUploaded byanoopjames123
- Chapter 6 Solutions ManualUploaded byMena Adel
- Part 1 of 1algerbra.docxUploaded bySteve Cook
- Sales and Profit PlanningUploaded bykoyalp

- Financial Management Report- Ravi Chandra Ghanta (1)Uploaded bySrinu Gattu
- Capital Investment and Financial Decisions sgg.pdfUploaded bysgd
- Offer Suggest ProposeUploaded byrkontessa
- White Label AtmUploaded byJiss Tom
- Statement of Cash FlowsUploaded byimad
- Fiscal Year 2013-2014 Adopted Annual Budget Revision 2_201404291003546998Uploaded bythe kingfish
- 30.pdfUploaded byTalin Machin
- Policy for Rehabilitation and resettlement of Land OwnersUploaded byrark
- VALUATION OF GOODWILL AND SHARES.docxUploaded byakshata
- ch15.pdfUploaded byRetno Tri Septiyani
- rarocUploaded byIan Qr
- Accounting Instructions PRIVATEUploaded byapi-3744408
- Ranciere - The Concept of 'Critique' and the 'Critique of Political Economy' (From the 1844 Manuscript to Capital)Uploaded byLeonardo Marques
- BCG Report on Indian BanksUploaded byபாபிரபாகரன்
- 0538476796_253699Uploaded byriko
- Notes on House PropertyUploaded byApoorvaChandra
- cima c4 puraniUploaded byAli Masood Arain
- Damodaran Online_ Home Page for Aswath DamodaranUploaded byleekiangyen
- Different Ownership structures.pptUploaded bySuman Poudel
- Rule: Final Flood Elevation DeterminationsUploaded byJustia.com
- AALI - ICMD 2010 (A01).pdfUploaded byArdheson Aviv Arya
- stdyguid (1).pdfUploaded byunsaarshad
- Business Risk ProjectUploaded byjosemartinez25
- KDF Foreign Valuation ExplanationUploaded byAnanthakumar A
- Finance Dept CircularsUploaded bysusanta_kumar
- Macro ArticlesUploaded bytheatresonic
- Sangam AmUploaded byPrabal
- Dhofar Power CompanyUploaded bylatifasaleem
- Philippines 05 Hrd CSRUploaded byjdrosel
- epfo RAFIUploaded byThillai Rajan