Ques
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:
*
* *
* *
* *
*
View Answers
January 10, 2011 at 2:50 PM
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
January 10, 2011 at 3:01 PM
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
January 10, 2011 at 3:08 PM
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
January 10, 2011 at 3:24 PM
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
January 10, 2011 at 3:25 PM
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);
}
}
January 10, 2011 at 3:28 PM
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)
January 10, 2011 at 5:47 PM
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
January 11, 2011 at 5:44 PM
check sum of alternate digit of number is palindrome or not?
January 12, 2011 at 3:03 PM
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
Related Tutorials/Questions & Answers:
Ques {
public static void main(String[] args) {
int num=3;
int p = num;
int
q = 0...;=
q; k++)
System.out.print(" ");
q+=1;
}
}
}
Thanks
Advertisements
provide me the program for that ques.provide me the program for that
ques. wtite a program in java there is a class readchar.the functionality of this class is to read a string from the console and display the characters of that string on the console.
give the code for this ques///give the code for this
ques/// write a program in java in which there is a clss readline. the functionality of this class is to read a string from the console and display it on the console .A point that should be keep in mind
give the code for this ques///give the code for this
ques/// write a program in java which contains a class simple. this class contains 4 members variables namely a,b,c,and d. This class also contains 3 constructors of 2,3 and 4 arguments and a function
about interview ques. - Java Interview Questionsabout interview
ques. i give a interview for java..
they ask me.
what is System.out.println();
what is its write ans... Hi Friend,
It is the syntax of Java used to display a string on the console window
jspjsp
ques: how to insert data into database using mysql
jspjsp
ques: how to insert data into database using mysql
jspjsp
ques: how to insert data into database using mysql
jspjsp
ques: how to insert data into database using mysql
Need Help on JMS - JMSNeed Help on JMS Hi, In my application i need to create my own
ques and my own QueueConnectionFactory..... Plz tell me how to create the same... Any help is appriciated,.. Thanks in advance
Important Interview Questions in Core Java with a fresher or having experience of 1-2 years. Read carefully:ADS_TO_REPLACE_1
Ques.../beginners/what-is-java.shtml
Ques: Is java platform Independent? Or What..., Linux, MacOS and Solaris etc.
Ques: What do you mean by platform independence
JSF Basic Interview Questions will improve the chances of your success. So have a look on it.
Ques: What is JSF...://www.roseindia.net/jsf/whatisjsf.shtml
Ques: What is required to get started with JSF...) such as Netbeans 5.5, Eclipse 3.2.x and others.ADS_TO_REPLACE_2
Ques: What is the JSF
patternspatterns who ever answered my previous
ques thank u sooooo much!!!!!!!!!!
though i was able to solve most complicated progms in java patterns are a night mare for me. thank u once again.can u help me on how to print
ONLINE EXAM CODE SPLITONLINE EXAM CODE SPLIT hi.. im developing online exam for c programming in jsp..
i read the question from database as a string
suppose
String
ques="#include<stdio.h>main(){int i;for(i=0;<100;i++){printf("hai
java - Java Beginnersjava
Ques-Give the output of the following code :
class numeric {
static int fact (int n)
{
int p=1;
int i=n;
while (i >=2)
{
i--;
p=p*i;
)
refurn p;
}
public static void main (String args [])
{
int X=4
Database Design `onlinexamination`;
Then create the table new_
ques which contains the queshon.
CREATE TABLE `new_
ques` (
`quesno` int(10
Java Virtual Machine(JVM);
Ques:-What is Java Virtual Machine?
Ans:- Java Virtual...
Ques 2:- JVM provides portability explain..?
Ans...; MyFirstProgram
OUTPUT ADS_TO_REPLACE_8
I am creating my first java program
Ques 3
jsp - JSP-ServletJSP, Servlet creating user account How to create user account in Java using JSP and Servlet? hi i think this is ans 4ur
ques try like this.i am sending u sample code<%@ page contentType="text/html; charset
hi ;<td><%=rs.getString("
ques")%></td><td><input type
jspjsp
ques: how to insert data into database using mysql
//index.jsp
<%--
Document : index
Created on : May 20, 2013, 1:20:04 PM
Author : ignite178
--%>
<%@page contentType="text/html
chn.ilp.test =(Map.Entry)itr.next();
QuestionVO
ques=(QuestionVO)me.getValue();;
%>
<...
ques=(QuestionVO)me.getValue();;
%>
<tr>
<td><