plz plz give coding for C CO COM COMP COMPU COMPUT COMPUTE COMPUTER & wap to print product of digits (212=212) &wap to compute sum of 1^2+2^2+4^2+8^2+10^2 . coding for:
*
* *
* *
* *
*
Hi Friend,
1)Try the following code:
import java.util.*;
class StringExample3
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter word: ");
String st=input.next();
for(int i=0;i<=st.length();i++){
int j=i+1;
System.out.println(st.substring(0,i));
}
}
}
Thanks
Hi FRiend,
2)Try the following code:
import java.util.*;
class ProductOfDigits
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter multidigit number: ");
long no=input.nextLong();
long p=1,i=0;
while(no>0)
{
i=no%10;
p=p*i;
no=no/10;
}
System.out.println("Product of digits: "+p);
}
}
Thanks
Hi Friend,
3)Try the following code:
class FindSum
{
public static void main(String[] args)
{
double sum=Math.pow(1,2)+Math.pow(2,2)+Math.pow(4,2)+Math.pow(8,2)+Math.pow(10,2);
System.out.println("Sum of 1^2+2^2+4^2+8^2+10^2 is: "+sum);
}
}
Thanks
he Hello;
Below is the code :
public class Example1 {
public static void main(String[] args) {
String str = "COMPUTER";
for (int i = 1; i < str.length()+1; i++) {
for (int j = 0; j < i; j++) {
System.out.print(str.charAt(j) + " ");
}
System.out.println();
}
}
}
Anuj Kumar
Hey;
Below is the code for 2nd prog:
import java.util.Scanner;
public class Example2 { public static void main(String[] args) {
int num;
System.out.println("Enter interger no: ");
Scanner scanner = new Scanner(System.in);
num = scanner.nextInt();
int pro = 1;
while (num != 0) {
pro *= (num % 10);
num = num / 10;
}
System.out.println("Product of digits: " + pro);
}
}
Hey;
Below is the code for Diamond Pattern;
public class Example3 {
public static void main(String[] args) {
int iMin = 0, iMax = 6;
int jMin = 0;
int count = 0;
int i, j, k, l;
for (i = iMax; i >= iMin; i--) {
count++;
for (j = jMin; j < i; j++)
System.out.print(" ");
System.out.print("* ");
for (k = 1; k < count; k++)
System.out.print(" ");
for (l = 1; l < count - 1; l++)
System.out.print(" ");
if (count > 1)
System.out.print("* ");
System.out.println();
}
for (i = iMin; i < iMax; i++) {
count--;
for (j = jMin; j <= i; j++)
System.out.print(" ");
System.out.print("* ");
for (l = 1; l < count; l++)
System.out.print(" ");
for (l = 1; l < count - 1; l++)
System.out.print(" ");
if (count > 1)
System.out.print("* ");
System.out.println();
}
}
}
I think this might be help full for you. :)
for the series one plzz specify more that it is series or just hard codes expression...
Anuj Kumar (Knapster)
Hi Friend,
4)Try the following code:
public class PatternExample {
public static void main(String[] args) {
int num=3;
int p = num;
int q = 0;
for (int i = 0; i <= num; i++) {
for (int j = p; j>= 1; j-- )
System.out.print(" ");
p-=1;
for (int k = 1; k <= i; k++)
System.out.print ("* ");
System.out.println();
}
num-=1;
for (int i = 0; i<=num; i++) {
for (int j = num; j > i; j--)
System.out.print (" *");
System.out.println();
for (int k = 0; k <= q; k++)
System.out.print(" ");
q+=1;
}
}
}
Thanks
check sum of alternate digit of number is palindrome or not?
Hi Friend,
Try this:
import java.math.*;
import java.util.*;
class CheckSumIsPalindrome{
public static void main(String[] args){
Scanner input=new Scanner(System.in);
System.out.print("Enter Number: ");
BigInteger bi=input.nextBigInteger();
int num = 0;
String strSum = bi.toString();
for(int i = 0;i < strSum.length(); i+=2){
char ch=strSum.charAt(i);
int n=Integer.parseInt(Character.toString(ch));
num+=n;
}
System.out.println("Sum of Alternate digits is: "+num);
int n = num;
int reversedNumber=0;
for (int i=0; i<=num; i++){
int r=num%10;
num=num/10;
reversedNumber=reversedNumber*10+r;
i=0;
}
if(n == reversedNumber){
System.out.print("Number is palindrome!");
}
else{
System.out.println("Number is not palindrome!");
}
}
}
Thanks