Skip to main content

Posts

Showing posts with the label 13.Write a Java program to swap first and last digits of a number.

ads1

13.Write a Java program to swap first and last digits of a number.

  13.Write a Java program to swap first and last digits of a number. Static :-   class loop13 { public static void main(String args[]) { int n=1234,ld,ft,temp; ld = n%10; System.out.println("last number :- "+ld); ft = n; while(ft>=10) { ft = ft/10; } System.out.println("First  number :- "+ft); temp=ld;   ld =ft;    ft =temp;    System.out.println("last number :- "+ld); System.out.println("First  number :- "+ft); } } Output :-  Dynamic :-  import java.util.*; class loop13 { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n,ld,ft,temp; System.out.println("Enter the number :-  "); n=in.nextInt(); ld = n%10; System.out.println("Last Digit :-"+ld); ft=n; while(ft>=10) { ft = ft/10; } System.out.println("First Digit :-"+ft); temp=ld; ld=ft; ft=temp;System.out.println("last number

ads2