0% found this document useful (0 votes)
19 views

QWQWQWQWQWQW

sr

Uploaded by

Maybeitsjaden
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

QWQWQWQWQWQW

sr

Uploaded by

Maybeitsjaden
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

T4Q4

public static void main(String[] args) {


System.out.println("Enter a number");
Scanner scanner=new Scanner(System.in);
int num=scanner.nextInt(); //cin>>num;
int sum=0, digit;
sumDigits(num);

while(num>0){
digit=num%10;
sum=sum+digit;
num/=10;

}
System.out.println("The sum of its digit is "+sum);

}
public static int sumDigits ( int num){

if(num>0){
return sumDigits(num/10)+num%10;
}
return 0;

}
}

T4Q5
public static void main(String[] args){
// Scanner scanner=new Scanner(System.in);
// System.out.println("Enter base: ");
// int base=scanner.nextInt();
// System.out.println("Enter exponent: ");
// int ex=scanner.nextInt();
// int result=1;
//// for(int i=1;i<=ex;i++){
//// result=result*base;
//// }
// System.out.println(base+ " to the power of "+ex+" is "+power(base,ex));
//
// }
//
// public static double power(int b, int e){
// if(e<0) return 1.0/power(b,e*-1);
// if(e>0){
// return power(b, e-1)*b;
// }
// return 1;
// }
//}

You might also like