153= 1^3+5^3+3^3 5 mins some important call came 2 mins please ============================== 153%10 =3 153/10 = 15 fetch the last digit cube the digit add that cube to the sum remove the last digit you need to do to process till my n not equal to 0 ================================= public class Sample { public static void main(String[] args) throws NumberFormatException, IOException { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int sum=0; int temp=n; //1234 while(n!=0) { int rem=n%10; sum=sum+rem*rem*rem; n=n/10; } if(temp==sum) { System.out.println("Armstrong Number"); }else { System.out.println("Not Armstrong"); } } } ===================================================== Prime number : a number having factors 1 and itself is called prime number n= Its having 2 factors n (1 to n) n=23 1 2 3 .................23 calculate count of number of factors count==2 its a prime number ================================================= n= 2 lakh 2 to n/2 if you find atleast one factor you can break the loop 50 2 to 25 ===================================== 35 2 17 ==================================== 100 50 after 50 can you find =================== 24 12 ================================================= package basic; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; //Prime number public class Sample { public static void main(String[] args) throws NumberFormatException, IOException { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int count=0; for(int i=2;i<=n/2;i++) { if(n%i==0) { count++; break; } } if(count==1) { System.out.println("Its not a prime number"); }else { System.out.println("Its a Prime number"); } } } ===================================================================== 1 lakh to 50k Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int count=0; for(int i=2;i<=(int)Math.sqrt(n);i++) { if(n%i==0) { count++; break; } } if(count==1) { System.out.println("Its not a prime number"); }else { System.out.println("Its a Prime number"); } ================================================================== n=5 ***** ***** ***** ***** ***** we need Vars, ifelse , for , nested for , arrays , strings , collections ===================================================================== package basic; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; //Prime number public class Sample { public static void main(String[] args) throws NumberFormatException, IOException { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int count=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { System.out.print("*"); } System.out.println(); } } } ==================================================== 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4 5 5 5 5 5 ================================================== package basic; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; //Prime number public class Sample { public static void main(String[] args) throws NumberFormatException, IOException { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int count=0; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { System.out.print(i+" "); } System.out.println(); } } } ======================================================