class Stack: def __init__(self): self.items = [] def is_empty(self): return len(self.items) == 0 def push(self, item): self.items.append(item) print(f"Pushed: {item}") def pop(self): if not self.is_empty(): popped_item = self.items.pop() print(f"Popped: {popped_item}") return popped_item else: print("Stack is empty. Cannot pop.") def display(self): if not self.is_empty(): print("Stack Contents:") for item in reversed(self.items): ...
Posts
Palindrome Number
- Get link
- X
- Other Apps
Java Program to check whether the entered Number entered by user is Palindrome or Not. package whileLoops; import java.util.Scanner; public class PalindromeNumber { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("Enter a number:"); int n=input.nextInt(); int temp=n; int reversed=0; while(temp>0) { int lastDigit=temp%10; reversed=reversed*10+lastDigit; temp/=10; } if(reversed==n) System.out.println("Yes ,"+n+" is a Palindrome Number"); else System.out.println("No ,"+n+" is not a P...
Sum of Digits
- Get link
- X
- Other Apps
Java Program to find Sum of Digits of Number entered by user. package whileLoops; import java.util.Scanner; public class SumOfDigits { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("Enter a number:"); int n=input.nextInt(); int temp=n; int sum=0; while(temp>0) { int lastDigit=temp%10;//lastDigit=2 temp/=10;//temp=54 sum+=lastDigit;//sum=2 } System.out.println("Sum of digits in "+n+" is "+sum); } }
Power
- Get link
- X
- Other Apps
Java Program to find X raised to the power Y, where X and Y are entered number by user. package loops; import java.util.Scanner; public class Power { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.println("Enter two numbers:");//2 4 int a=input.nextInt();//x=2 int b=input.nextInt();//y=4 int result=1; for(int i=1;i<=b;i++) { result*=a; } System.out.println(a+" power "+b+" is "+result); } }
Decimal Number to Binary Number
- Get link
- X
- Other Apps
Java Program to find Binary Number of the Decimal Number entered by user. package loops; import java.util.Scanner; public class DecimalToBinary { public static void main(String[] args) { //Program to Convert the user Decimal Number to Binary Number Scanner input=new Scanner(System.in); System.out.println("Enter a number:"); int n=input.nextInt(); //n=200 System.out.print("Binary Number of "+n+" is "); int temp=n;//temp=200 for(int i=1073741824;i>0;i/=2)//i=0 //n=36 { if(i<=temp)//i=8 { System.out.print("1"); temp-=i;//temp=0 } else if(i<n) System.out.print("0"); } } }
Calculator
- Get link
- X
- Other Apps
Java Program to make a Simple Calculator. package conditionalStatements; import java.util.Scanner; class Calculator { public static void main(String[] args) { Scanner input=new Scanner(System.in); double num1,num2,result=0; System.out.println("\t\t\tCalculator\n\nEnter First number:"); num1=input.nextDouble(); System.out.println("Enter Second number:"); num2=input.nextDouble(); System.out.println("Enter an Operator(+ - * / %) :"); input.nextLine(); char operator=input.nextLine().charAt(0); switch(operator) { case '+': result=num1+num2; break; case '-': result=num1-num2; break; case '*': result=num1*num2; break; case '/': ...
Simple Interest Calculator
- Get link
- X
- Other Apps
Java Program to make a Simple Interest Calculator . package practice; import java.util.Scanner; public class SimpleInterest { public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.print("\t\t\tSimple Interest\n\nEnter the Principal(in INR):"); float principal=scan.nextFloat(); System.out.print("Enter the time(in year):"); int time=scan.nextInt(); System.out.print("Enter the rate of interest(out of 100%):"); float interest=scan.nextFloat(); System.out.println("Simple Interest is "+"\""+(principal*time*interest/100)+"\""+"\n\n\t\t\tTotal Amount is "+"\""+((principal*time*interest/100+principal))+"\""); } } Keep Coding Keep Smiling :)