Skip to main content

Java program to display formatted output


Suppose the tuition for a university is $5,000 this year and increases 4.5% every year. Write a program that displays the tuition for the next four years. Display two digits after the decimal point.

public class Q1
{
        public static void main(String args[])
        {
                double fee=5000;

                for(int i=0;i<4;i++)
                {
                        fee=(fee*0.045) + fee;
                        System.out.format("Increased fee for %d year = $%6.2f%n",(i+1),fee);
                }
        }
}


Comments

Popular posts from this blog

Use Case Diagram for Online Book Store

Occurrences of each letter of alphabet in the text

Program to print a table indicating the no. of occurrences of each letter of alphabet in the text entered as command line arguments. #include<iostream> #include<string> using namespace std; int main(int argc, char *argv[]) { string str=""; static int alphabet[26]; int x; cout<<"\n\n Command-Line Argument\n"; for(int i=0;i<argc;i++) { cout<<"\n "<<argv[i]; str+=argv[i]; } for(int i=0;i<str.length();i++) { if(str[i]>='A' && str[i]<='Z') { x=((int)str[i])-65; alphabet[x]++; } else if(str[i]>='a' && str[i]<='z') { x=((int)str[i])-97; alphabet[x]++; } } //Displaying No. of occurrences of each alphabets in the command line argument cout<<"\n\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n Alphabet No. of Occurrences\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; for(int i=0;i<26;i++)...

How to Run SQL Command Line in Oracle 10g

Step 1: Goto start button  then program menu. Step 2:  Expand Oracle.                             Step 3: Select “ Run SQL Command Line”. Step 4: Now type in SQLPlus command prompt following commands: - a)       Type   connect b)       Enter username as “ System” c)       Then, Enter password of your Oracle 10g               Step 5: Now execute your SQL commands. e.g. : -