0% found this document useful (0 votes)
10 views

Java 1

Uploaded by

suhasm11111111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Java 1

Uploaded by

suhasm11111111
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

1.......

import java.util.Scanner;

class Student_Grade {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter The Five Subject Marks :");

int m1 = input.nextInt();
int m2 = input.nextInt();
int m3 = input.nextInt();
int m4 = input.nextInt();
int m5 = input.nextInt();

int tot = m1 + m2 + m3 + m4 + m5;


// Use float or double for the total to avoid integer division
float per = (tot / 500.0f) * 100; // Changed to 500.0f for correct division

System.out.println("Total: " + tot);


System.out.println("Percentage: " + per);

if (per >= 90 && per <= 100) {


System.out.println("Grade A");
} else if (per >= 80 && per < 90) { // Changed to < 90 for clarity
System.out.println("Grade B");
} else if (per >= 70 && per < 80) { // Changed to < 80 for clarity
System.out.println("Grade C");
} else if (per >= 60 && per < 70) { // Changed to < 70 for clarity
System.out.println("Grade D");
} else if (per >= 40 && per < 60) { // Changed to < 60 for clarity
System.out.println("Grade E");
} else {
System.out.println("Grade F");
}

input.close(); // It's good practice to close the scanner


}
}

2...........
import java.util.Scanner;

public class Person {


// Fields
private String name;
private int age;

// Constructor
public Person(String name, int age) {
this.name = name;
this.age = age;
}

// Method to display information


public void displayInfo() {
System.out.println("Name: " + name);
System.out.println("Age: " + age);
}

public static void main(String[] args) {


Scanner input = new Scanner(System.in);

// Prompting user for name and age


System.out.print("Enter your name: ");
String name = input.nextLine();

System.out.print("Enter your age: ");


int age = input.nextInt();

// Creating an instance of Person using the constructor


Person person1 = new Person(name, age);

// Displaying information using the displayInfo method


person1.displayInfo();

input.close(); // Closing the scanner


}
}

You might also like