Explain with an example the if-else-if construct in java language?
The If else if construct is usually used when a series of conditions need to be validated or checked one by one.
Say for example you are writing a program to decide on projected weight of a person then you may need to have an if - else if block.
If height > 4 feet then
weight should be atleast 40 kgs
else if height > 5 feet then
weight should be atleast 50 kgs
else if height > 6 feet then
weight should be atleast 60 kgs
and so on...
Example code.
This method takes the height in inches as input and returns weight in kilograms as output.
public int getMinWeight(int height){
if(height > 4) {
return 40;
} else if(height > 5){
return 50;
} else if (height > 6){
return 60;
} else {
return 70;
}
}
Can you have two mains in java?
Yes...
We can have more than one main in JAVA...
Just make the only one main method as public and other as default access specifier....
public class Test
{
public static void main(String args[])
{
}
}
class Test1
{
public static void main(String args[])
{
}
}
class Test2
{
public static void main(String args[])
{
}
}
Just copy the above code and try....
Have fun in learning... :-) :) :-)
Write a C program to implement relocatable loader?
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
struct object_code
{
int locctr;
char add[10];
}obcode[300];
void main()
{
char input[100][16],output[100][16],binary[20],address[20],stloc[10];
int len,bitmask,loc,tlen=0,tloc,textloc,i=0,location,j,k,count=0,start,n,num=0,inc=0;
FILE *fp1,*fp2;
clrscr();
fp1=fopen("linput.dat","r");
fp2=fopen("reloadout.dat","w");
printf("Enter the location where the program has to be loaded:");
scanf("%s",stloc);
start=atoi(stloc);
location=start;
tloc=start;
fscanf(fp1,"%s",input[i]);
while(strcmp(input[i],"T")!=0)
{
strcpy(output[i],input[i]);
i++;
fscanf(fp1,"%s",input[i]);
strcpy(output[i],input[i]);
}
itoa(start,output[2],10);
while(strcmp(input[i],"E")!=0)
{
strcpy(output[i],input[i]);
if(strcmp(input[i],"T")==0)
{
for(j=0;j<3;j++)
{
i++;
fscanf(fp1,"%s",input[i]);
strcpy(output[i],input[i]);
}
bitmask=atoi(output[i]);
itoa(bitmask,binary,2);
strcpy(output[i],NULL);
textloc=atoi(output[i-2]);
textloc=textloc+start;
itoa(textloc,output[i-2],10);
for(n=0;n<(textloc-(tloc+tlen));n++)
{
strcpy(obcode[inc].add,"xx");
obcode[inc++].locctr=location++;
}
tlen=atoi(output[i-1]);
tloc=textloc;
k=0;
}
else
{
if(binary[k]==1)
{
num=0;
len=strlen(output[i]);
strcpy(address,NULL);
for(j=2;j<len;j++)
{
address[num]=output[i][j];
output[i][j]='\0';
num++;
}
loc=atoi(address);
loc=loc+start;
itoa(loc,address,10);
strcat(output[i],address);
}
k++;
len=strlen(output[i]);
num=0;
for(n=0;n<len;n++)
{
obcode[inc].add[num++]=output[i][n];
if(num>1)
{
obcode[inc++].locctr=location++;
num=0;
}
}
}
i++;
fscanf(fp1,"%s",input[i]);
}
strcpy(output[i],input[i]);
i++;
fscanf(fp1,"%s",input[i]);
loc=atoi(input[i]);
loc=loc+start;
strcpy(output[i],itoa(loc,address,10));
count=0;
i=0;
n=0;
fprintf(fp2,"%d\t",obcode[n].locctr);
for(n=0;n<inc;n++)
{
fprintf(fp2,"%s",obcode[n].add);
i++;
if(i>3)
{
fprintf(fp2,"\t");
i=0;
count++;
}
if(count>3)
{
fprintf(fp2,"\n%d\t",obcode[n+1].locctr);
count=0;
}
}
getch();
}
What is the main method of transportation in Sweden?
Car is a very common method of transportation.
Cars, then public transportation.
How do you deal with installing Java Access Bridge?
So, I followed every instruction in oracle, yet when I try to install a program(which needs access bridge) it gives me this error:
java.awt.AWTError: Assistive Technology not found: com.sun.java.accessibility.AccessBridge
I did absolutely EVERYTHING in the oracle site about 5 times. Still won't work. Anyone can help?
//Perhaps this is what you want.
//@author Rosencrantz
import java.util.Scanner;
class TriangleFun
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
boolean done = false;
while(true)
{
System.out.print("Calculate AREA or PERIMETER? Type DONE to quit.");
String input = scan.nextLine().trim();
if(input.equalsIgnoreCase("DONE"))
break;
if(input.equalsIgnoreCase("AREA"))
{
System.out.print("Enter the base length: ");
double base = scan.nextDouble();
System.out.print("Enter the height: ");
double height = scan.nextDouble();
System.out.println("Area is: " + (1/2.0) * base * height);
}
else
{
System.out.print("Enter length of side 1: ");
double length1 = scan.nextDouble();
System.out.print("Enter length of side 2: ");
double length2 = scan.nextDouble();
System.out.print("Enter length of side 3: ");
double length3 = scan.nextDouble();
System.out.println("Perimeter is: " + (length1 + length2 + length3));
}
scan.nextLine();
}
}
}
//A better edited version is in the links
Java is a programming language which comes in many varieties. Some of the common ones are Micro Edition (ME), Standard Edition (SE), and Enterprise Edition (EE).
Java EE includes more classes than the other versions, including classes and packages designed to make developing client-server (and other internet-based communication) projects a faster process.
Java EE 5 just means the fifth major version of the Java EE suite.
There are several properties of matter that can help to identify it and can be easily tested or measured. First test for electrical conductivity and thermal conductivity. Also test for magnetism. If the substance is a non powdered solid, then calculate the volume using water and weigh the object to find the density.
Website of free java project to be download with source code?
which Website for free java project to be download with source code
Free Download Project in asp.net,Java ,C#.Net ,Php on thisWebsite www.enggroom.com
I read in Maximum PC magazine that white space will be a way for people too get free broadband internet and achieve up to 100mb/s of downloads. But there is a debate that white space will interfere with mikes and speakers in heavy populated areas. But dont be expecting to see this soon. It will probably, my guess, take around 6 to 7 years till its on the market
What are the three types of variables used in java?
Instance, Local and Class variables. They can be prefixed by keywords such as "final" or "transient" to govern the way their values are dealt with in Java. All these variable types have different scopes and visibilites. Locals are specific to a particular area in the code e.g. methods, instances are tied to a particular class and would contain values based on the state of the class at a given point in time and Class variables are like global variables which are independent of the state of the class at any time and as such will contain the same value unless, explicitly changed in the code. These variables are marked by "static" keyword and more often than not prefixed by keyword "final" to prevent programmatic change in the value for e.g. in the case of constant values like PI.
A character, or char, is single letter such as 'a'.
It's a primitive data type, like int and long, and the letter is always put inside single quotes ' '.
The class String, which is used for storing sentences, is made up of a whole bunch of char's put together.
When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. The way to allow two or more statements to be grouped into a transaction is to disable auto-commit mode
How methods with multiple parameters are declared?
The same as in C, with a comma-separated list of formal arguments enclosed in parenthesis.
Write a program to print all the prime numbers between n and m in java?
import java.io.*;
public class pmn {
public static void main(String[] args) throws Exception{
int i;
BufferedReader bf = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter number:");
int num = Integer.parseInt(bf.readLine());
System.out.println("Prime number: ");
for (i=1; i < num; i++ ){
int j;
for (j=2; j<i; j++){
int n = i%j;
if (n==0){
break;
}
}
if(i == j){
System.out.print(" "+i);
}
}
}
}
Data binding is basically a technique for binding two data/information sources together and maintaining a synchronization of data.
You usually achieve this with two data/information sources with different languages as in XML data binding or in fact using Java, Java UI elements to Java objects.
How do you convert jar file to sis?
this conversion is not possible
because sis is a symbian file(another operating system that is mainly used by nokia)
&
jar is java file
both are not same
What is the use of switch statement in java?
In java, a switch statement is used to simplify a long list of 'if' statements. A switch statement takes the form of:
switch (variableName){
case condition1; command1;
case condition2; command2;
...
}
Do you mean your Java installation keeps updating itself? If this is the case, then you have two options:
Is an EUE thread a Non-Pressure sealed thread?
EUE thread is a pressure sealed thread as usual completion pup joints thread
What kinds of members can a class have?
Members of a class may include
1. Static Methods
2. non-static methods
3. Instance variables
4. Sub classes
etc.