Sunday, March 22, 2015

Swap Digits from an Integer Number Using Constructor with parameter

Write a Java Program to swap digits from a given integer number. Use Constructor with parameter. Use necessary method and instance, if required.

Reference:

1.
Course Book(The Complete Reference Java j2se) ; Page 119

2.
http://c-programming-sourcecode.blogspot.com/2014/12/c-program-to-swap-numbers.html?updated-min=2014-12-01T00:00:00-08:00&updated-max=2015-01-01T00:00:00-08:00&max-results=41

Source Code:

package Swap;
import java.util.Scanner;

class Swapnum
{
int number;
Swapnum(int digit)
{
number=digit;
}
int get_Swap(){
int swa = 0;
int remainder = 0;
do{
remainder = number%10;
swa = swa*10 + remainder;
number = number/10;
}while(number > 0);
return swa;
}
}
public class Swap {

public static void main(String args[]) {
Scanner input =new Scanner(System.in);
int number;
System.out.println("Please enter number to be Swap using Parameterized Constructor: ");
number = input.nextInt();
Swapnum r =new Swapnum(number);
System.out.println("After Swap : "+r.get_Swap());
}
}

18 comments:

  1. ID-201420406
    Batch:46th
    class Box
    {
    double width;
    double height;
    double depth;
    Box(double w, double h, double d) {
    width = w;
    height = h;
    depth = d;
    }
    double volume() {
    return width * height * depth;
    }
    }
    class BoxDemo7 {
    public static void main(String args[]) {
    Box mybox1 = new Box(1, 5, 10);
    Box mybox2 = new Box(3, 6, 9);
    double vol;
    vol = mybox1.volume();
    System.out.println("Volume is " + vol);
    vol = mybox2.volume();
    System.out.println("Volume is " + vol);
    }
    }

    ReplyDelete
  2. MD:Rashed Prodhania
    Batch:46th
    ID:201420763

    class Box
    {
    double width;
    double height;
    double depth;
    Box(double w, double h, double d)
    {
    width = w;
    height = h;
    depth = d;
    }
    double volume() {
    return width * height * depth;
    }
    }
    class BoxDemo7
    {
    public static void main(String args[]) {
    Box mybox1 = new Box(10, 20, 15);
    Box mybox2 = new Box(3, 6, 9);
    double vol;
    vol = mybox1.volume();
    System.out.println("Volume is " + vol);
    vol = mybox2.volume();
    System.out.println("Volume is " + vol);
    }
    }

    ReplyDelete
    Replies
    1. ID: 201420763
      Batch : 46th

      package javaapplication11;


      public class JavaApplication11 {


      public static void main(String[] args) {
      int input1 = sum(5,10);
      int input2 = sum(5,5,20);
      int input3 = sum(10,10,20,50);
      System.out.println("Under the Display Your Input Addition: ");
      System.out.println("1st input Addition:");
      System.out.println(input1 );
      System.out.println("2nd input Addition:");
      System.out.println(input2 );
      System.out.println("3rd input Addition:");
      System.out.println(input3 );

      }
      private static int sum(int... args)
      {
      int ret = 0;

      if (args != null)
      {
      for (int val : args)
      {
      ret += val;
      }
      }
      return ret;
      }

      }

      Delete
  3. ID-201421066
    Batch:46th

    class Bx
    {
    double width;
    double height;
    double depth;
    Bx(double w, double h, double d) {
    width = w;
    height = h;
    depth = d;
    }
    double volume() {
    return width * height * depth;
    }
    }
    class BxDemo7 {
    public static void main(String args[]) {
    Bx mybox1 = new Bx(4, 7, 20);
    Bx mybox2 = new Bx(8, 6, 30);
    double ad;
    ad = mybox1.volume();
    System.out.println("Volume is " + ad);
    ad = mybox2.volume();
    System.out.println("Volume is " + ad);
    }
    }

    ReplyDelete
  4. batch-46th
    ID-201420270
    class Box
    {
    double width;
    double height;
    double depth;
    Box(double w, double h, double d) {
    width = w;
    height = h;
    depth = d;
    }
    double volume() {
    return width * height * depth;
    }
    }
    class BoxDemo7
    {
    public static void main(String args[]) {
    Box mybox1 = new Box(1, 2, 5);
    Box mybox2 = new Box(3, 6, 9);
    double vol;
    vol = mybox1.volume();
    System.out.println("Volume is " + vol);
    vol = mybox2.volume();
    System.out.println("Volume is " + vol);
    }
    }

    ReplyDelete
  5. ID-201420405
    Batch-46th
    class Box
    {
    double width;
    double height;
    double depth;
    Box(double w, double h, double d)
    {
    width = w;
    height = h;
    depth = d;
    }
    double volume()
    {
    return width * height * depth;
    }
    }
    class BoxDemo7
    {
    public static void main(String args[]) {
    Box mybox1 = new Box(10, 20, 30);
    Box mybox2 = new Box(3, 6, 9);
    double vol;
    vol = mybox1.volume();
    System.out.println("Volume is " + vol);
    vol = mybox2.volume();
    System.out.println("Volume is " + vol);
    }
    }

    ReplyDelete
  6. class Boss
    {
    double width;
    double height;
    double depth;

    Boss (double w, double h, double d )
    {
    width = w;
    height = h;
    depth = d;
    }
    double volume()
    {
    return width*height*depth;
    }
    }
    class Bossdemo7{
    public static void main(String[] args) {
    Boss n1=new Boss(5, 5, 10);
    Boss n2=new Boss(2, 5, 9);

    double vol;
    vol=n1.volume();
    System.out.println("Volume is=" + vol);

    vol=n2.volume();
    System.out.println("Volume is=" + vol);

    }
    }

    ReplyDelete
  7. package Swap;
    import java.util.Scanner;

    class Swapnum
    {
    int number;
    Swapnum(int digit)
    {
    number=digit;
    }
    int get_Swap(){
    int swa = 0;
    int remainder = 0;
    do{
    remainder = number%10;
    swa = swa*10 + remainder;
    number = number/10;
    }while(number > 0);
    return swa;
    }
    }
    public class Swap {

    public static void main(String args[]) {
    Scanner input =new Scanner(System.in);
    int number;
    System.out.println("Please enter number to be Swap using Parameterized Constructor: ");
    number = input.nextInt();
    Swapnum r =new Swapnum(number);
    System.out.println("After Swap : "+r.get_Swap());
    }
    }

    ReplyDelete
  8. Q:Write a Java Program to swap digits from a given integer number.
    Use Constructor with parameter.
    Use necessary method and instance, if required.

    package Swap;
    import java.util.Scanner;

    class Swapnum
    {
    int N;
    Swapnum(int digit)
    {
    N=digit;
    }
    int get_Swap()
    {
    int swa = 0;
    int remainder = 0;
    do{
    remainder = N%20;
    swa = swa*20 + remainder;
    N = N/20;
    }
    while(N > 0);
    return swa;
    }
    }
    public class Swap
    {
    public static void main(String args[])
    {
    Scanner input =new Scanner(System.in);
    int N;
    System.out.println("Please enter N to be Swap using Parameterized Constructor: ");
    N = input.nextInt();
    Swapnum r =new Swapnum(N);
    System.out.println("After Swap : "+r.get_Swap());
    }
    }

    ReplyDelete
  9. ID-201421068
    Batch-46th

    class Box
    {
    double width;
    double height;
    double depth;
    Box(double w, double h, double d) {
    width = w;
    height = h;
    depth = d;
    }
    double volume() {
    return width * height * depth;
    }
    }
    class BxDemo7 {
    public static void main(String args[]) {
    Box mybox1 = new Box(2, 8, 40);
    Box mybox2 = new Box(5, 8, 20);
    double re;
    re = mybox1.volume();
    System.out.println("Volume is " + re);
    ad = mybox2.volume();
    System.out.println("Volume is " + re);
    }
    }

    ReplyDelete
  10. package numberswapping;
    import java .util.Scanner;
    class work
    {
    work(int number)
    {
    int rem=0;
    int n=number;
    Scanner inp=new Scanner(System.in);
    System.out.print("Enter the integer number which u are trying to swap:");
    n=inp.nextInt();
    while(n!=0)
    {
    rem=rem*10;
    rem=rem+n%10;
    n=n/10;
    }
    System.out.println("after swaping the number is :" +rem);
    }

    }
    public class Numberswapping
    {
    public static void main(String[] args)
    {
    int n=0;
    work w=new work(n);

    }

    }

    ReplyDelete
  11. Yeasmin Akter
    ID:201420271
    Bach:46th
    Q:Write a Java Program to swap digits from a given integer number.
    Use Constructor with parameter.
    Use necessary method and instance, if required.

    package Swap;
    import java.util.Scanner;

    class Swapnum
    {
    int N;
    Swapnum(int digit)
    {
    N=digit;
    }
    int get_Swap()
    {
    int swa = 0;
    int remainder = 0;
    do{
    remainder = N%20;
    swa = swa*20 + remainder;
    N = N/20;
    }
    while(N > 0);
    return swa;
    }
    }
    public class Swap
    {
    public static void main(String args[])
    {
    Scanner input =new Scanner(System.in);
    int N;
    System.out.println("Please enter N to be Swap using Parameterized Constructor: ");
    N = input.nextInt();
    Swapnum r =new Swapnum(N);
    System.out.println("After Swap : "+r.get_Swap());
    }
    }
    Reply

    ReplyDelete
  12. write a program to sum of 3 integer namber using paramiter

    yeasmin akter
    ID:201420271
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package javaapplication12;

    /**
    *
    * @author Student
    */
    public class JavaApplication12 {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    int yeasmin1 = sum(2,5);
    int yeasmin2 = sum(23,25,10);
    int yeasmin3 = sum(5,20,13,20);
    System.out.println(yeasmin1 + yeasmin2 + yeasmin3 );

    }
    private static int sum(int... args)
    {
    int ret = 0;

    if (args != null)
    {
    for (int val : args)
    {
    ret += val;
    }
    }
    return ret;
    }

    }

    ReplyDelete
  13. Name : Main Uddin
    ID - 201421090
    Batch - 46th

    package ex.pkg6;
    //import java.util.Scanner;
    import java.util.Scanner;
    class MAIN
    { int a;
    MAIN(int GTR)
    { a=GTR;}
    void swap(MAIN CTG)
    {
    int temp=a;
    a=CTG.a;
    CTG.a=temp;
    }
    }
    public class EX6 {
    public static void main(String[] args) {
    MAIN obj1=new MAIN(5);
    MAIN obj2=new MAIN(7);
    System.out.println("Before Swap integer value........");
    System.out.println("obj1 has integer value->"+obj1.a);
    System.out.println("obj2 has integer value->"+obj2.a);
    obj1.swap(obj2);
    System.out.printf("\n");
    System.out.println("After Swap integer value........");
    System.out.println("obj1 has integer value->"+obj1.a);
    System.out.println("obj2 has integer value->"+obj2.a);
    }

    }

    ReplyDelete
  14. MD: jalis Mahmud
    ID : 201420762
    Batch : 46th



    package numberswapping;
    import java .util.Scanner;
    class work
    {
    work(int number)
    {
    int rem=0;
    int a=number;
    Scanner inp=new Scanner(System.in);
    System.out.print("Enter the integer number which u are trying to swap:");
    a=inp.nextInt();
    while(a!=0)
    {
    rem=rem*20;
    rem=rem+a%20;
    a=a/20;
    }
    System.out.println("after swaping the number is :" +rem);
    }

    }
    public class Numberswapping
    {
    public static void main(String[] args)
    {
    int a=0;
    work w=new work(a);

    }

    }

    ReplyDelete
  15. Name : Habibur Rahaman
    ID-201421091
    Batch-46

    package ex.pkg6;
    //import java.util.Scanner;
    import java.util.Scanner;
    class sajib
    { int m;
    sajib(int UTM)
    { m=UTM;}
    void swap(sajib UTM)
    {
    int temp=m;
    m=UTM.m;
    UTM.m=temp;
    }
    }
    public class EX6 {
    public static void sajib(String[] args) {
    sajib obj1=new sajib(10);
    sajib obj2=new sajib(15);
    System.out.println("Before Swap integer value........");
    System.out.println("obj1 has integer value->"+obj1.m);
    System.out.println("obj2 has integer value->"+obj2.m);
    obj1.swap(obj2);//this should swap using call by reference
    System.out.printf("\n");
    System.out.println("After Swap integer value........");
    System.out.println("obj1 has integer value->"+obj1.m);
    System.out.println("obj2 has integer value->"+obj2.m);
    }

    }

    ReplyDelete
  16. Id-201421092
    Batch-46

    package ex.pkg6;
    //import java.util.Scanner;
    import java.util.Scanner;
    class ROni
    { int m;
    ROni(int UTM)
    { m=UTM;}
    void swap(ROni UTM)
    {
    int temp=m;
    m=UTM.m;
    UTM.m=temp;
    }
    }
    public class EX6 {
    public static void sajib(String[] args) {
    ROni obj1=new ROni(10);
    ROni obj2=new ROni(15);
    System.out.println("Before Swap integer value........");
    System.out.println("obj1 has integer value->"+obj1.m);
    System.out.println("obj2 has integer value->"+obj2.m);
    obj1.swap(obj2);//this should swap using call by reference
    System.out.printf("\n");
    System.out.println("After Swap integer value........");
    System.out.println("obj1 has integer value->"+obj1.m);
    System.out.println("obj2 has integer value->"+obj2.m);
    }

    }

    ReplyDelete