Java program to find compound interest?
public class SimpleInterest{
float principal,intRate, numOfYears;
public void setPrincipal(float principal){
this.principal = principal;
}
public void setIntRate(float intRate){
this.intRate = intRate;
} public void setNumOfYears(float numOfYears){
this.numOfYears = numOfYears;
} public float calculateSimpleInterest(){
return (this.principal * this.intRate * this.numOfYears) /100; } public static void main(String argv[]){
float principal,intRate, numOfYears;
SimpleInterest simpIntObj = new SimpleInterest();
principal = Float.parseFloat(argv[0]);
intRate = Float.parseFloat(argv[1]);
numOfYears = Float.parseFloat(argv[2]);
simpIntObj.setPrincipal(principal);
simpIntObj.setIntRate(intRate);
simpIntObj.setNumOfYears(numOfYears);
System.out.println ("Principal = "+principal);
System.out.println ("Interest Rate = "+intRate);
System.out.println ("Num of Years = "+numOfYears);
System.out.println ("Simple Interest Amount = "+simpIntObj.calculateSimpleInterest());
} }
String reverse program with single string and without using library functions in java?
You can create a separate string initially empty. Then using a loop, start at the end of the string and add it to the end of the other string. At the end of the loop, the other string would contain the reverse.
What are the advantage of data type double over data type int?
double data type is: a double precision floating point number, positive and negative, and covers a much larger range.
However there are limitations to the precision of any representation of a floating point number, because all floating point representations are based on negative powers of 2 and the sums of negative powers of 2 i.e. 1/2 is represented as 2-1, 1/4 is represented as 2-2, but 1/3 is the sum of 1/4 + 1/16 + 1/64, etc (the sum of all negative even powers of 2) to the limit of the precision provided by the floating point representation.
Where the double outweighs the int data type is that it can express very large integer numbers without loss of precision.
In terms of processing time to perform operations on each data type, there are no benefits in using the double - it occupies 64 bits (8 bytes) of RAM vs 32 bits (4 bytes) of RAM for the int.
Original answerAs It Is Quite Clear that The range Of Double pricisionNumber IS More Than that Of INT....So When We use Double
Over The int ...its Whole Space (that is reserved Somewhere
in the Memory that is Further recalled By Compiler) Just
Gets double of it.........
Benefit is.......Its useful In Program Codes To Avoid BUGs..
Loss Is..........takes DOUBLE Space in memory Allocation as compared to INT..........
String concaination program using pointers in C?
#include<stdio.h>
#include<conio.h>
void main()
{
char a[5][10];
int i;
clrscr();
for(i=0;i<5;i++)
{
printf("enter %d string",i+1);
scanf("%s",&a[i]);
}
for(i=0;i<5;i++)
{
printf("\n%s",a[i]);
}
getch();
}
Write a program that accepts a number and output its equivalent in words?
/*mycfiles.wordpress.com
program to convert digits to character*/
#include
#include
void main()
{
int a[5],i,n;
clrscr();
cout<<"Enter the Value";
cin>>n;
for(i=4;i>=0;i--)
{
a[i]=n%10;
n=n/10;
}
for(i=0;i<5;i++)
{
if(a[i]!=0)
{
switch(a[i])
{
case 0:cout<<"Zero";
break;
case 1:cout<<"One";
break;
case 2:cout<<"Two";
break;
case 3:cout<<"Three";
break;
case 4:cout<<"Four";
break;
case 5:cout<<"Five";
break;
case 6:cout<<"Six";
break;
case 7:cout<<"Seven";
break;
case 8:cout<<"Eight";
break;
case 9:cout<<"Nine";
break;
}
}
}
getch();
}
------------------------------------------------------------------------------------
Program to Convert Numbers into Words
#include
void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};
void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}
void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}
// for any query visit
// "http://www.c.happycodings.com/Beginners_Lab_Assignments/code51.html"
Program to Convert Numbers into Words
#include
void pw(long,char[]);
char *one[]={" "," one"," two"," three"," four"," five"," six"," seven","
eight"," Nine"," ten"," eleven"," twelve"," thirteen"," fourteen","
fifteen"," sixteen"," seventeen"," eighteen"," nineteen"};
char *ten[]={" "," "," twenty"," thirty"," forty"," fifty"," sixty","
seventy"," eighty"," ninety"};
void main()
{
long n;
clrscr();
printf("
Enter any 9 digit no: ");
scanf("%9ld",&n);
if(n<=0)
printf("Enter numbers greater than 0");
else
{
pw((n/10000000),"crore");
pw(((n/100000)%100),"lakh");
pw(((n/1000)%100),"thousand");
pw(((n/100)%10),"hundred");
pw((n%100)," ");
}
getch();
}
void pw(long n,char ch[])
{
(n>19)?printf("%s %s ",ten[n/10],one[n%10]):printf("%s ",one[n]);
if(n)printf("%s ",ch);
}
// for any query visit
// "http://www.c.happycodings.com/Beginners_Lab_Assignments/code51.html"
Why applet tag is used in java program?
Applets are designed to be embedded within web browsers. The obvious advantage here is the ability to run a Java program directly in your web browser, without having to manually launch a completely separate program.
Inheritance is an object oriented feature supported by Java wherein the features of one Java class can be inherited/made available in another class. This creates a parent child relationship between these 2 classes. Class Inheritance in java mechanism is used to build new classes from existing classes. The inheritance relationship is transitive: if class x extends class y, then a class z, which extends class x, will also inherit from class y. Object-oriented programming allows classes to inherit commonly used state and behavior from other classes.
Example:
public class Parent {
private String name = "Rocky";
public String getName(){
return this.name;
}
}
public class Child extends Parent {
public static void main(String[] args){
System.out.println("Name in Parent is: " + getName());
}
}
Here the getName() method is available only in the parent class but is directly used in the child class because the method is public and is directly accessible to the child class since it has extended the parent class.
Benefits of Inheritance:
One of the key benefits of inheritance is to minimise the amount of duplicate code in an application by sharing common code amongst several subclasses. Where equivalent code exists in two related classes, the hierarchy can usually be refactored to move the common code up to a mutual superclass. This also tends to result in a better organisation of code and smaller, simpler compilation units.
Inheritance can also make application code more flexible to change because classes that inherit from a common superclass can be used interchangeably. If the return type of a method is superclass
What do you need to download to start programming in java?
There exists a variety of software to help you begin writing in the Java language. One of the more well known software brands is Oracle which provides a complete step by step walk-through to help you learn as you go.
What is the definition of java program?
I will assume that you mean in a broad spectrum in this answer.
Java is intended to be a cross-platform full programming language.
It has the three (or four) control structures necessary for any program:
Sequence, Descisions, and Loops (and Modules, functions and classes).
This means that it can make programs similar to anything that you have
come across, albeit, some tricks may need to be used for some of them.
Also, due to a huge GUI API, Java is also very capable in creating programs
similar to WordPad or many of the games you may find online. As a matter
of fact, a lot of those games are written in Java.
No. I don't work for Oracle or Sun Microsystems, I just like Java...
How can you print 5 54 543 5432 54321 in java using for loop?
With two nested loops. In the outer loop, a variable - we might call it "n" - would go from 5 down to 1, in the inner loop, the variable (whatever you call it) goes from 5 down to n. Write out each digit in the inner loop; in the outer loop you need to add the extra space.
J2EE = enterprise edition jdk. J2SE = standard edition jdk. J2ME = mobile edition jdk. standard jdk gets used for platform development, enterprise jdk for enterprise development and mobile jdk gets used for mobile development.
Can return statement be in a void method in java?
the main method in java is the client code therefore doesn't return any values Unlike languages like C/C++, the user doesn't specify an error return code by returning from the main method. Instead they should use System.exit(code) to do this. If the Java main method returns, the default code of zero is returned.
What is the difference between an array of structures and an array within a structure?
The main differences between an array and a structure are:
An Array is a collection of similar data items.An array is derived data type.It behave like a built in data type. An array can be increased or decreased.
A structure is a collection of dissimilar data items.It is a user defined data types.It must be declared and defined.A structure element can be added if necessary.
What is the difference between Web UI and Java?
Java Virtual Machine (JVM) is exactly as it's titled, it's just a virtual machine... while Windows is an operating system.
But since the JVM is used to run Java code, it is multi-platform.
What is difference between multi character constant and string literals?
In C, you can assign integers multiple characters such that they fit in their size. For e.g.:
int - 4 bytes
char - 1 byte
So an assignment like this is valid:
int a = 'ABCD';
The first byte in a will be assigned the value of 'A', the second - 'B' and so on.
A string literal is a character array constant. It is enclosed in double quotes and assignment can only be made to a char pointer. There is no limit on the size of the literal and it is terminated with a null character. e.g.:
char str[] = "This is a trial";
What can be declared in an abstract class?
Abstract classes are to be extended until to a concrete class.
Can have both abstract & non abstract methods.
An Abstract class can not be instantiated.
A non abstract class can be extended to an abstract class.
If At least one abstract method present in a class then that class must be abstract.
abstract & final modifiers can never be together.
abstract classes can have both abstract methods & non abstract methods.
How many data types can the elements of an array have?
Depends on your language. Assuming java: If you make it an Object[] then it can contain any object
For primitive types you must either make a primitive type array, ie double[], char[] which can contain only those primitives, or creater an Object[] and use primitive wrapper objects ie java.lang.Integer etc.
Is Java a Language or Package?
Actually, it is both.
Visual Basic is a Microsoft only programming language. In order to run programs written in VB though, you may need the VB runtime library as a package DLL even if you don't use the language itself.
What is the Program for compare two strings using OR operator in java?
The String class includes two helpful methods: equals and compareTo.
string1.equals(string2) will return true if the two strings contain the exact same characters
string1.compareTo(string2) will return an int which describes the lexicographic relationship between the two strings. It will return a negative value if string1 is "less than" string2, a positive value if string1 is "greater than" string2, or zero if the two are equivalent strings.
What is BufferedReader in java?
The BufferedReader class is used for fast reading operations of texts from a character-input stream. It can be used to read single characters, arrays, and lines of data. The size of buffer may or may not be specified. The readLine() method of the BufferedReader class can be used to get the next line of characters from a file, and the skip(long n) method can be used to skip n number of characters.
How do you write a java program to find the maximum number in an array?
int[] nums; // assume this is an array of length 5 and you want to find the largest
// finding it with a loop
int max = nums[0];
for(int i = 1; i < nums.length; ++i) {
if(nums[i] > max) {
max = nums[i];
}
}
// max is now the largest
// finding it manually
int max = Math.max(nums[0], Math.max(nums[1], Math.max(nums[2], Math.max(nums[3], nums[4]))));
// ugly, but effective
Can static variables be changed?
No, a static variable means that there is only one copy of that variable, and it is shared by all members of the class, or by all callers of a function.
A variable that is read-only would be marked as const or final (depending on language).
What is diff between method and class?
method is a process
property is about it.
please check the answer from others also. because its only my guess.
SORRY
THANK YOU
What is the difference between a global scope and a local scope?
Scope refers to the accessibility of an object. A globally scoped object is available globally (to the entire program) while a locally scoped object is only available locally (to the containing function or class). In general, you want to avoid global objects whenever possible as it tends to introduce dependencies.
How do you write a java program to find a area of geometrical figure using method overloading?
import java.io.*;
public class Driven
{
static void main(String args[])throws IOException
{
InputStreamReader read=new InputStreamReader(System.in);
BufferedReader in= new BufferedReader(read);
System.out.println(" please enter length");
int a=Integer.parseInt(in.readLine());
System.out.println(" please enter breadth");
int b=Integer.parseInt(in.readLine());
int c=a*b;
System.out.println("The area of rectangle is "+c);
}
}
// when you run this program then in main menu to run this program write {} and then press ok