0
I need help in writing an algorithm
You must write an algorithm that will ask the user to enter a number that is greater than 999 (at least 4 has digits). The algorithm will then output the third last digit of the number. Example if the user enters 38702, then the algorithm will output 7. Your algorithm will not have to worry about error checking to make sure that the user enters a number with at least three digits, assume they will always enter a correct value. To solve this problem you will need to use integer division and modulus operators
4 odpowiedzi
+ 5
x/100%10
There you go...
+ 1
import java.util.Scanner ;
public class Program
{
public static void main(String[] args) {
Scanner in=new Scanner(System.in) ;
int inp=in.nextInt() ;
int leng=(int) Math.log10(inp)+1;
int po=(int) Math.pow(10,leng-3);
int pos=(inp /po)%10;
System.out.println(pos);
}
}
0
"To solve this problem you will need to use integer division and modulus operators"
It basically tells you what to do...
What do you have so far? Or what exactly is the problem?
0
I just need help in writing the pseudocode algorithm. I am learning pseudocode but I didn't understand this one.