write a program that inputs two real numbers then exchanges
their values.

Answers were Sorted based on User's Feedback



write a program that inputs two real numbers then exchanges their values...

Answer / pratibha.v

class Swap
{
public static void main(String[] args)
{
int a,b,temp;
System.out.println("Enter the two nors\n");
a=Integer,parseInt(args[0]);
b=Integer.parseInt(args[1]);
System.out.println("Values of and b are"+a,+b);
temp=a+b;
System.out.println("temp=="+temp);
a==temp-b;
b==temp-a;
System.out.println("The value of a after Swapping are"+a);
System.out.println("The value of b after Swapping are"+b);
}
}

Is This Answer Correct ?    15 Yes 8 No

write a program that inputs two real numbers then exchanges their values...

Answer / pradip kr singh

class Swap
{
public static void main(String[] args)
{
int a,b,temp;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
System.out.println("Values of a and b are "+a+" , "+b);
temp=a+b;
System.out.println("temp=="+temp);
a=temp-a;
b=temp-b;
System.out.println("The value of a after Swapping are "+a);
System.out.println("The value of b after Swapping are "+b);
}
}

Is This Answer Correct ?    10 Yes 7 No

write a program that inputs two real numbers then exchanges their values...

Answer / chirag

import java.io.*;
class swap
{
public static void main(String df[]) throws IOException
{
int a,b,temp;
BufferedReader c1=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the 1st number:");
a=Integer.parseInt(c1.readLine());
System.out.println("Enter the 2nd number:");
b=Integer.parseInt(c1.readLine());
temp=a;
a=b;
b=temp;
System.out.println("after changing the values are:");
System.out.println("value of 1st number:"+a);
System.out.println("value of 2nd number:"+b);
}
}

Is This Answer Correct ?    4 Yes 2 No

write a program that inputs two real numbers then exchanges their values...

Answer / purnachandrareddy

class Swap1
{
int a,b,temp;
void set(int x,int y)
{
a=x;
b=y;
System.out.println("enter the value of a= "+a);
System.out.println("enter the value of b="+b);
}
void change()
{
temp=a+b;
a=temp-a;
b=temp-b;
System.out.println("swap value of a= "+a);
System.out.println("swap value of b="+b);
}
}
class swap
{
public static void main(String[] args)
{
if(args.length != 2)
System.out.println("plz enter two values");
else
{
int x=Integer.parseInt(args[0]);
int y=Integer.parseInt(args[1]);
Swap1 s=new Swap1();
s.set(x,y);
s.change();
}
}
}

Is This Answer Correct ?    6 Yes 6 No

write a program that inputs two real numbers then exchanges their values...

Answer / pratibha.v

class Swap
{
public static void main(String[] args)
{
int a,b,temp;
System.out.println("Enter the two nors\n");
a=Integer,parseInt(args[0]);
b=Integer.parseInt(args[1]);
System.out.println("Values of and b are"+a,+b);
temp=a+b;
System.out.println("temp=="+temp);
a==temp-a;
b==temp-b;
System.out.println("The value of a after Swapping are"+a);
System.out.println("The value of b after Swapping are"+b);
}
}

Is This Answer Correct ?    6 Yes 7 No

write a program that inputs two real numbers then exchanges their values...

Answer / guindy friends

package Balu.vinoth.manic.Rama;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Pract {

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

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter Prabhakaran salary:");
int firstValue = Integer.parseInt(br.readLine());

System.out.println("Enter Jeyamurugan salary:");
int secondValue = Integer.parseInt(br.readLine());

firstValue = firstValue + secondValue;

secondValue = firstValue - secondValue;
firstValue = firstValue - secondValue;

// After Swapping
System.out.println("Prabhakaran salary :" + firstValue);
System.out.println("Jeyamurugan salary :" + secondValue);

}

}

Is This Answer Correct ?    1 Yes 2 No

write a program that inputs two real numbers then exchanges their values...

Answer / pradeep

class Swap1
{
int a,b;
void setNumbers(int x,int y)
{
a=x;
b=y;
System.out.println("values of a & b: "+a+", "+b);
}
void change()
{
a=a+b;
b=a-b;
a=a-b;
System.out.println("swap values of a & b: "+a+", "+b);
}
}
class swap
{
public static void main(String[] args)
{
if(args.length != 2)
System.out.println("plz enter two values");
else
{
int x=Integer.parseInt(args[0]);
int y=Integer.parseInt(args[1]);
Swap1 s=new Swap1();
s.set(x,y);
s.change();
}
}
}

Is This Answer Correct ?    2 Yes 4 No

Post New Answer

More J2SE Code Interview Questions

how to print a message to console without using main() function?(do not use even static blocks also.)

14 Answers   Google, Zoho,


how to create a (*)pyramid using java codes???

5 Answers   Infosys,


does anyone know the code to display a triangle using a applet?

1 Answers  


Design a program using one-dimensional array that determines the highest value among the eight input values from a user. Display the difference of each value from the highest to the lowest.

1 Answers   RoboSoft,


How Can I Trace A Java Program . Please Give Me Step by Step Process

1 Answers   IBM,






Program to print map of India in java.

2 Answers  


write a program that inputs two real numbers then exchanges their values.

7 Answers   Infosys,


write a program in java to solve a system of n-variabled simultaneous equations using the guassian elimination method. let the maximum possible value of n be 100. run the program using hypothetical values for a set of 10- variables simultaneous equations. print out the program, the input equation and the results generated by the program.

0 Answers   TCS,


we compile any program bu c:/>javac prog.java and run as c:/>java prog Here what's the meaning of c in javac. We have java Interpreter but not compiler.Then why we have to use javac. Please answer this question?

2 Answers  


I am trying to pass the string firstName from a Servlet called SampleServet. I am running this on eclipse and it tells me that "the value for annotation attribute must be a constant expression. I don't understand why it is giving me this error. @PersonAnnotation(name = SampleServlet.firstName) public class AnnotationClass{

0 Answers  


what are the other loops except for for,while,do while and until?

0 Answers   Aricent,


Is it possible to define marker interface in java.If possible then how to define user defined marker interface?

1 Answers   Tech Mahindra,


Categories