Posts

Showing posts from June, 2025

Write a Java program in which you input students name, class, roll number, and marks in 5 subjects. Find out the total marks, percentage, and grade according to the following table. Percentage Grade >= 90 A+ >= 80 and < 90 A >= 70 and < 80 B+ >= 60 and < 70 B >= 50 and < 60 C >= 40 and < 50 D < 40 E

Image
 import java.util.Scanner; public class q21 {     public static void main(String args[ ])      {         Scanner in = new Scanner(System.in);         System.out.print("Enter name of student: ");         String n = in.nextLine();         System.out.print("Enter class of student: ");         int c = in.nextInt();         System.out.print("Enter roll no of student: ");         int r = in.nextInt();         System.out.print("Enter marks in 1st subject: ");         int m1 = in.nextInt();         System.out.print("Enter marks in 2nd subject: ");         int m2 = in.nextInt();         System.out.print("Enter marks in 3rd subject: ");         int m3 = in.nextInt();         System.out.print(...

Write a menu driven program to accept a number from the user and check whether it is a Buzz number or an Automorphic number. i. Automorphic number is a number, whose square's last digit(s) are equal to that number. For example, 25 is an automorphic number, as its square is 625 and 25 is present as the last two digits. ii. Buzz number is a number, that ends with 7 or is divisible by 7.

Image
 import java.util.Scanner; public class q20 {     public static void main(String args[ ])      {         Scanner in = new Scanner(System.in);         System.out.println("1. Buzz number");         System.out.println("2. Automorphic number");         System.out.print("Enter your choice: ");         int choice = in.nextInt();         System.out.print("Enter number: ");         int num = in.nextInt();         switch (choice)          {             case 1:             if (num % 10 == 7 || num % 7 == 0)                 System.out.println(num + " is a Buzz Number");             else                 System.out.printl...

Write a java program using scanner method, to read and display the following details: Name -- as a String data type ; ROLLNO-- as a integer data type ; Enter marks of 5 subjects-- as a float data type Compute and display the percentage of marks.

Image
 import java.util.*; class q5 {     public static void main(String args[ ])     {         Scanner sc=new Scanner(System.in);         System.out.println("ENTER YOUR NAME");         String n=sc.next();         System.out.println("ENTER YOUR ROLL NO.");         int r=sc.nextInt();         System.out.println("ENTER YOUR MARKS OF FIVE SUBJECTS");         float m1=sc.nextFloat();         float m2=sc.nextFloat();         float m3=sc.nextFloat();         float m4=sc.nextFloat();         float m5=sc.nextFloat();         float t=(m1+m2+m3+m4+m5)/5 *100;         System.out.println("TOTAL PERCENT="+t);        } } PROGRAM : OUTPUT:

Write a program in Java that accepts the seconds as input and converts them into the corresponding number of hours, minutes and seconds. A sample output is shown below: Enter Total Seconds: 5000 1 Hour(s) 23 Minute(s) 20 Second(s)

Image
 import java.util.*; class q4 {     public static void main(String args[ ])     {         Scanner sc=new Scanner(System.in);         System.out.println("ENTER TIME IN SECONDS");         int t=sc.nextInt();         int m=t/60;         int h=m/60;         m=m%60;         int s=t%60;         System.out.print("  hour="+h);         System.out.print("  minutes="+m);         System.out.print("  seconds="+s);     } } PROGRAM : OUTPUT:  

Write a program in Java that takes input using the Scanner class to calculate the Simple Interest and the Compound Interest with the given values: i. Principle Amount = Rs.1,00,000 ii. Rate = 11.5% iii. Time = 5 years Display the following output: i. Simple interest ii. Compound interest iii. Absolute value of the difference between the simple and compound interest.

Image
import java.util.Scanner; public class q1 {     public static void main(String[ ] args)      {         Scanner in = new Scanner(System.in);         System.out.print("Enter Principal: ");         double p = in.nextDouble();         System.out.print("Enter Rate: ");         double r = in.nextDouble();         System.out.print("Enter Time: ");         int t = in.nextInt();                  double si = p * r * t / 100.0;         double cAmt = (p * Math.pow(1 + (r / 100), t));         double ci = cAmt - p;         double diff = Math.abs(si - ci);                  System.out.println("Simple interest = " + si);         System.out.println("Compound interest = " + ci...

Write a program to compute the Time Period (T) of a Simple Pendulum as per the following formula: T = 2π√(L/g) Input the value of L (Length of Pendulum) and g (gravity) using the Scanner class.

Image
PROGRAM :  import java.util.*; class q2 {     public static void main(String args[ ])     {         Scanner sc=new Scanner(System.in);         System.out.println("ENTER LENGTH OF PENDULUM");         double l=sc.nextDouble();         System.out.println("ENTER THE GRAVITY");         double g=sc.nextDouble();         double t=2*3.14*Math.sqrt(l/g);         System.out.println("TIME OF PENDULUM:"+t);     } } OUTPUT :

Write a Java Program to print the ASCII values from the numbers 1 to 150.

Image
Program  class ascii {     public static void main(String args[])     {         for(int i=1;i<=150;i++)         {             System.out.println(i+"\t"+(char)i);         }     } } Program Window Output