Write a program that reads an integer and displays, using asterisks, a filled di
ID: 3864963 • Letter: W
Question
Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 4, the program should Currency conversion. Write a program that first asks the user to type today's price for one dollar in Japanese yen, then reads U.S. dollar values and converts each to yen. Use 0 as a sentinel. Write a program that first asks the user to type in today's price of one dollar in Japanese yen, then reads U.S. dollar values and converts each to Japanese yen. Use 0 as the sentinel value to denote the end of dollar inputs. Then the program reads a sequence of yen amounts and converts them to dollars. The second sequence is terminated by another zero value. The Monty Hall Paradox. Marilyn vos Savant described the following problem (loosely based on a game show hosted by Monty Hall) in a popular magazine:Explanation / Answer
1) Star Problem
package as3;
import java.util.Scanner;
public class DiamondPattern
{
public static void main(String args[])
{
int n, i, j, space = 1;
System.out.print("Enter the number of rows of Star and Diamond: ");
Scanner s = new Scanner(System.in);
n = s.nextInt();
space = n - 1;
for (j = 1; j <= n; j++)
{
for (i = 1; i <= space; i++)
{
System.out.print(" ");
}
space--;
for (i = 1; i <= 2 * j - 1; i++)
{
System.out.print("*");
}
System.out.println("");
}
space = 1;
for (j = 1; j <= n - 1; j++)
{
for (i = 1; i <= space; i++)
{
System.out.print(" ");
}
space++;
for (i = 1; i <= 2 * (n - j) - 1; i++)
{
System.out.print("*");
}
System.out.println("");
}
}
}
2)
package as3;
import java.util.Scanner;
public class CurrencyConvertor
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Today's price of one dollor in japanese YEn");
double yen=sc.nextDouble();
// 1 usd =112.55 yenn
for(int i=0;i<2;i++){
//5000
System.out.println("Enter amount of yen you want to convert in USD");
double yenAmount=sc.nextDouble();
//112.55 yenn == 1 usd so 5000 yenn =44.42 usd
double dollor= yenAmount/yen;
System.out.println(dollor);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.