Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How To Make This Program
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Harish Lodhi
How To Make This Program
2 Answer(s)      6 years and 11 months ago
Posted in : Java Beginners


How To Make Java Calculation program
I want to Write a program in Java that calculates the sum of digits of an input number, prints it, then calculates the sum... output: 59 14 5 please help to make this program


Advertisement
View Answers

February 23, 2008 at 1:17 PM


import java.io.*;
import java.lang.*;
class stringnumber{
public static void main(String args[])throws IOException
{
int i,a=0,b,n=0,count=0;
String y,kh="0";

/* INPUT FROM THE KEYBOARD */

InputStreamReader obj=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(obj);
System.out.println("enter the number");
String ch=br.readLine();
a=ch.length();
for(count=0;count<=a;count++)
{
System.out.println(" the num entered is"+"\t"+"\t"+ ch);
System.out.println(" the string length is"+"\t"+ch.length());

/* SPERATING THE STRINGS .CONVERTING THE STRINGS TO INTEGERS.ADDITION OF

THE INTEGERS */

for(i=0;i<a;i++)
{
System.out.println(" the seperated strings

are"+"\t"+ch.charAt(i));
Character c = new Character(ch.charAt(i));
String s = c.toString();
b = Integer.parseInt(s);
n=n+b;
y=Integer.toString(n);
kh=y;
}
n=0;
System.out.println(" the sum is"+"\t"+kh);
ch=kh;
System.out.println(" new string is"+"\t"+ch);
a=kh.length();
System.out.println(" the new length now is "+"\t"+a);
}
System.out.println(" the remaining single digit number is "+"\t"+ch);
}
}


February 23, 2008 at 1:20 PM


if u don't understand any part , feel free to ask me
bye.


Related Tutorials/Questions & Answers:
how to make a program on array
how to make a program on array  When you make a program on array that the element will move downward and upward and when you input twice 0 then thats the time that it will not move. pls. give me a formula...tnx
How To Make This Program - Java Beginners
How To Make This Program  How To Make Java Calculation program I want to Write a program in Java that calculates the sum of digits of an input number, prints it, then calculates the sum... output: 59 14 5 please help to make
Advertisements
make a program
make a program  GoodEmployee is defined who has ALL the following properties: He should be married. He should have 2 or less than 2 children. His middle name should start with "k" but not end with "e" The last name should have
make this program in java
make this program in java  given array a[1,5,3,1].want to take value from array and print star(*) that number times columm wise . output shuld
how to make this pattern???
how to make this pattern???  how to make following pattern in javascript
How to make elements invisible ?
How to make elements invisible ?   How to make elements invisible
how make ID - Ajax
how make ID  how make a ID in eyeball chat
how to make exampage in jsp ?
how to make exampage in jsp ?  how to make a online exam page in jsp and servelet
How to make selectOneMenu scrollable
How to make selectOneMenu scrollable  how to make the selectOneMenu scrollable? I have around 20 values in drop down and i want the scrollable functionality after 5 values. Kindly reply as soon as possible. Thanks Shikha
how make excel
how make excel  how make excel spreadsheet IN JAVA. please send this code argently   Hello Friend, Try the following code: import java.io.*; import org.apache.poi.hssf.usermodel.HSSFSheet; import
how to make multiple rectangles
how to make multiple rectangles  I,m a beginner , m sorry if the question is really simple i have an array list.I want to print the contents...(JFrame.EXIT_ON_CLOSE); //Set JFrame size setSize(400,400); //Make JFrame
how to make paging with function ?
how to make paging with function ?  how to make paging with function ?   //this page is display.php <?php</p> $con=mysql_connect("localhost","root",""); if(!$con) { die("you can connect please check". mysql
How to make directory in java
Description: This example demonstrate how to create a directory at specified...; } } Output: The result of this program is that it will make a dir at root directory of C drive
how to make a label left alignment?
how to make a label left alignment?  how to make a label left alignment
how to make a field left justification
how to make a field left justification  how to make a field left justification.need code.thanks in advance
How to make a chain, make a chain, chain
How to make a chain       To learn how to design a chain in the photoshop has become so easy by this example, it has some important instruction to make it so follow
how to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax
How to make bubbles, make bubbles, bubbles
How to make bubbles      ... to make it easily to draw. New File: First take colored background file. Draw... Overlay, use same both settings as given below. Duplicate: Now make
How to make a transparent text
How to make a transparent text Learn how to make a transparent...) and make formatting as looking here. Write Text: Now write your text as you like. I have written here "Text". After writing text make copy (Ctr
How to make halo effect
How to make halo effect       Now get ready to learn a simple way to make a halo effect on the picture, follow to make it. Take a picture: Capture any picture to give
How to make a bone, make a bone, a bone
How to make a bone       This example bone design example, It is very easy. If you are looking for, please follow now. New File: Create a new file. Rounded rectangle
how to make multiple choice questions
how to make multiple choice questions  I have to make a multiple choice choice using JSP/Servlets. I created a a session bean for the questions and answers. how to associate group of questions to a user? so each user will have
How to Make iPhone Window Application
How to Make iPhone Window Application  Hi, For Making iphone window application, what parameters i have to follow or provide example related to iphone window application. Thanks
How to make query and abstraction in Java
How to make query and abstraction in Java  Hi, I read the lessons you have in the sites. They are really useful. However, I could not write codes... PostgreSQL database, and I want to make a query and abstraction for a table. Could
How to make a button of different behaviour?
How to make a button of different behaviour?  Suppose In a jsp page I have a button SAVE with id="btnSave" value="SAVE" and a javascript function... ajaxInsertUpdateData(document.getElementByID("btnSave1").value,......); How to do
how to make combinations - Development process
how to make combinations  import java.util.*; interface Expression { public void interpret(ArrayList exp); } class OrExpression implements...; Hi friend, In your Program having many error and plz check it like
how to make employee i card
how to make employee i card  hello friends can anyone help me.. I have to make a project to make Identity card for employees...but i am facing problems with database and jsp connection ... also tell me how to retrive data
how to make paging with class and ajax
how to make paging with class and ajax  paging with class and ajax... displayLinks($show){ $this->show = $show; // How many links to show... displayLinks($show){ $this->show = $show; // How many links
How to make a design document for exception handling in java
How to make a design document for exception handling in java  How to make a design document for exception handling
How to make a Rectangle type pdf
How to make a Rectangle type pdf       In this program we are going to tell you how we can....  To make a program over this, firstly we need to import some packages
how can i make monthly register ?
how can i make monthly register ?  how can i make monthly register ? iam using jdeveloper
 

 

 

DMCA.com