Top Post

6/recent/ticker-posts

Java Problems solutions with full source code | IUB java Assignments


DOWNLOAD ALL FILES BY CLICK ON THE BELOW BETTON:



 
1.Write an application that reads three integers and prints their average.


package Eaglesoft;

import java.util.Scanner;

public class Q1 {
    public static void main(String[] args) {
        int a,b,c;
        float avg;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter first integer :");
        a=sc.nextInt();

        System.out.println("Enter second integer :");
        b=sc.nextInt();

        System.out.println("Enter Third integer :");
        c=sc.nextInt();

        avg=a+b+c/3;

        System.out.println("Average of A B and C is :");
        System.out.println(avg);
    }

}


2.• Write an application that prompts for and reads a person’s name, age, college,
and pet’s name. Then print the following paragraph, inserting the appropriate
data:
Hello, my name is name and I am age years old.
I’m enjoying my time at college, though I miss my pet petname very much!


package Eaglesoft;

import java.util.Scanner;

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

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter your name:");
        String name=sc.nextLine();

        System.out.println("Enter your College name :");
        String col=sc.nextLine();

        System.out.println("Enter you pet name :");
        String pet=sc.nextLine();

        System.out.println("Enter your Age :");
        int age=sc.nextInt();

        System.out.println("************************Your Details is************************");
        System.out.println("Hello, my name is " + name+ " and I am "+ age + " years old.");
        System.out.println("I’m enjoying my time at " + col + ", though I miss my pet " + pet + " very much!\n");
    }
}

3.• Write an application that reads two floating point numbers and prints their sum,
difference, and product:


package Eaglesoft;

import java.util.Scanner;

public class Q3 {
    public static void main(String[] args) {
            float a,b;
            float sum,dif,pro;
            Scanner sc=new Scanner(System.in);

            System.out.println("Enter first number:");
            a=sc.nextFloat();

            System.out.println("Enter second number :");
            b=sc.nextFloat();


            sum=a+b;
            dif=a-b;
            pro=a*b;

            System.out.println("Sum of A and b is :"+ sum);
            System.out.println("Difference of A and b is :"+ dif);
            System.out.println("Product of A and b is :"+ pro);
    }
}

4.Create a version of the TempConverter application to convert from Fahrenheit to
Celsius. Read the Fahrenheit temperature from the user:


package Eaglesoft;

import java.util.Scanner;

public class Q4 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        System.out.println("Enter temprature in Fahrenhite");
        double f=sc.nextFloat();

        double celsius = (f-32)*(0.5556);

        System.out.println("Temprature in celsius :" + celsius);

    }
}

5.• Write an application that converts miles to kilometers. (One mile equals 1.60935
kilometers.) Read the miles value from the user as a floating point value:

package Eaglesoft;

import java.util.Scanner;

public class Q5 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        System.out.println("Enter your Distance in Miles");
        float miles=sc.nextFloat();

        double km=miles*1.60935;

        System.out.println("Your Distance in KM is : " + km);
    }
}

6.• Write an application that prompts for and reads integer values for speed and
distance traveled, then prints the time required for the trip as a floating point
result:


package Eaglesoft;

import java.util.Scanner;

public class Q6 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        System.out.println("Enter you Distance :");
        int dis=sc.nextInt();

        System.out.println("Enter you Speed :");
        int speed=sc.nextInt();

        int time=dis/speed;

        System.out.println("You have need " + time + " hours for trip" );
    }
}

7.Write an application that reads values representing a time duration in hours,
minutes, and seconds and then prints the equivalent total number of seconds.
(For example, 1 hour, 28 minutes, and 42 seconds is equivalent to 5322 seconds.):


package Eaglesoft;

import java.util.Scanner;

public class Q7 {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        System.out.println("Enter Hours:");
        int h=sc.nextInt();

        System.out.println("Enter Minutes:");
        int m=sc.nextInt();

        System.out.println("Enter Seconds:");
        int s=sc.nextInt();

        h=h*60*60;
        m=m*60;
        int totalSeconds=h+m+s;

        System.out.println("Total Seconds is : "totalSeconds);

    }
}

Post a Comment

0 Comments