• Post Reply Bookmark Topic Watch Topic
  • New Topic

Program finished and compiled but need detailed help  RSS feed

 
Michael Adedire
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


import java.util.Scanner;

public class SplitNum{
public static void main(String[] args){

Scanner input = new Scanner(System.in);

System.out.print("Enter a 2 Digit integer");

int number = input.nextInt();

int ones = number / 10; // I THINK I MESSED UP RIGHT HERE

double tens = number / 10;

double sum = ones + tens;

System.out.println("The ones digit is " + ones + " , the number in the tens place is " + tens + " , and the sum of"
+ " the ones digit and the tens digit is " + sum);
System.out.println("Michael Adedire");
}
}



instructions

Program 3: SplitNum.java
Write a program that reads in a 2 digit integer (10 - 99). Your program should then print just
the number in the ones place, then on the next line just the number in the tens place, then on
the third line prints the sum of the two numbers. (Hint: Reminder division)
 
Ashish Dutt
Ranch Hand
Posts: 172
Java MySQL Database Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Michael,
Welcome to the Java Ranch.
That's an interesting problem however the next time when you post a problem please provide details on 'what is the problem that you are experiencing?'
Gauging by the code and the question that you have posted, I can see some obvious problems.
My suggestion to you would be to study the modulus operator for that is the key to this problem. Modulus Operator
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To find digit at ones place use % operator(number%10), to find digit at tens place use
int tens = number/10

Manish
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!