1) Write a program tat reads a four digit integer, such as 1998 ,and then displa
ID: 3542999 • Letter: 1
Question
1) Write a program tat reads a four digit integer, such as 1998 ,and then displays it, one digit per line so:
1
9
9
8
Your prompt should tell the user to enter a four-digit integer. You can then assume that the user follows directions. (Hint remainder operators.)
2) Repeat the previous project, but read the four digit integer as a string. Use String methods of the hint.
3) Write a program that converts degrees from Fahrenheit to Celsius, using the formula
formula
DegreesC = 5(DegreesF ?32)/9
Prompt the user to enter a temperature in degrees Fahrenheit as a whole number without a fractional part. Then have the program display the equivalent Celsius temperature, including the fractional part to at least one decimal point. A possible dialogue with the user might be
Enter a temperature in degrees Fahrenheit: 72
72 degrees Fahrenheit is 22.2 degrees Celsius.
Please no complicated programs, this is a beginners level java programming.
Explanation / Answer
Program 1:
import java.util.*;
import java.lang.*;
import java.io.*;
class Data
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner read=new Scanner(System.in);
System.out.println("Enter 4 digit number:");
int n=read.nextInt();//read integer from user
int Four = n/1000;
int Remainder3 = n % 1000;
int Three = Remainder3/100;
int Remainder2 = Remainder3 % 100;
int Two = Remainder2/10;
int Remainder1 = Remainder2 % 10;
int>
int Remainder0 = Remainder1 / 1;
int Zero = Remainder0;
System.out.printf("%d %d %d %d %d", Four, Three, Two, Zero);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.