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

Experiment 1 simple java program

The document contains three simple Java programs: one to check if a number is a palindrome, another to determine if a year is a leap year, and a third to calculate student grades based on their marks. Each program includes user input, logic for the respective calculations, and outputs the results. Additionally, the document features a repeated section for the student marks program, which collects names and marks, assigns grades, and prints the results.

Uploaded by

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

Experiment 1 simple java program

The document contains three simple Java programs: one to check if a number is a palindrome, another to determine if a year is a leap year, and a third to calculate student grades based on their marks. Each program includes user input, logic for the respective calculations, and outputs the results. Additionally, the document features a repeated section for the student marks program, which collects names and marks, assigns grades, and prints the results.

Uploaded by

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

EXPERIMENT:1

SIMPLE JAVA PROGRAM

1.PALINDROME NUMBER:

import java.util.Scanner;
public class Palindromenumber {

public static void main(String[] args) {


Scanner scanner=new Scanner(System.in);
System.out.print("enter a number:");
int num=scanner.nextInt();
scanner.close();
int originalnum=num;
int reversednum=0;
while(num!=0){
int digit=num%10;
reversednum=reversednum*10+digit;
num/=10;}
if(originalnum==reversednum){
System.out.println(originalnum+"it is a palindrome number");}
else{
System.out.println(originalnum+"it is not a palindrome number");}

OUTPUT:
Enter a number: 1221
1221 it is a Palindrome number

2.LEAP YEAR
import java.util.Scanner;
public class Leapyear {

public static void main(String[] args) {


Scanner scanner=new Scanner(System.in);
System.out.print("enter a number:");
int year=scanner.nextInt();
scanner.close();
if((year%4==0&&year%100!=0)||(year%400==0)){
System.out.println(year +"is a leap year");
}
else{
System.out.println(year +"it is not a leap year");}
}
}

OUTPUT:
Enter a Year: 2004
It is a Leap Year

3.ARMSTRONG NUMBER:
import java.util.Scanner;
public class Armstrongnumber {

public static void main(String[] args) {


Scanner scanner=new Scanner(System.in);
System.out.print("enter a number:");
int num=scanner.nextInt();
scanner.close();
int originalnum=num;
int sum=0;
int numofdigits=(int)Math.log10(num)+1;
while(num!=0){
int digit=num%10;
sum+=Math.pow(digit,numofdigits);
num/=10;}
if(originalnum==sum){
System.out.println(originalnum+"it is armstrong number");}
else{
System.out.println(originalnum+"it is not armstrong number");
}
}
OUTPUT:
Enter the number: 234
234 is not an Armstrong number

3.STUDENT’S MARK

import java.util.Scanner;

public class MarkList {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of students: ");

int numStudents = scanner.nextInt();

scanner.nextLine(); // Consume the newline character

// Initialize arrays to store student names, marks, and grades

String[] names = new String[numStudents];

double[] marks = new double[numStudents];

char[] grades = new char[numStudents];

// Input student names and marks

for (int i = 0; i < numStudents; i++) {

System.out.print("Enter name for student " + (i + 1) + ": ");

names[i] = scanner.nextLine();

System.out.print("Enter marks for student " + (i + 1) + ": ");

marks[i] = scanner.nextDouble();

scanner.nextLine(); // Consume the newline character


// Calculate grade based on marks

if (marks[i] >= 90) {

grades[i] = 'A';

} else if (marks[i] >= 80) {

grades[i] = 'B';

} else if (marks[i] >= 70) {

grades[i] = 'C';

} else if (marks[i] >= 60) {

grades[i] = 'D';

} else {

grades[i] = 'F';

scanner.close();

System.out.println("Mark List:");

// Print student information and grades

for (int i = 0; i < numStudents; i++) {

System.out.println("Name: " + names[i]);

System.out.println("Marks: " + marks[i]);

System.out.println("Grade: " + grades[i]);

System.out.println();

}
}

OUTPUT

Enter the number of students:2

Enter the name of the student Bob

Enter the mark of the student:80

Enter the name of the student :Ron

Enter the mark of the student:65

Mark list

Name : Bob

Mark : 80

Grade : B

Name : Ron

Mark : 65

Grade :D

3.STUDENT’S MARK

import java.util.Scanner;

public class MarkList {


public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the number of students: ");

int numStudents = scanner.nextInt();

scanner.nextLine(); // Consume the newline character

// Initialize arrays to store student names, marks, and grades

String[] names = new String[numStudents];

double[] marks = new double[numStudents];

char[] grades = new char[numStudents];

// Input student names and marks

for (int i = 0; i < numStudents; i++) {

System.out.print("Enter name for student " + (i + 1) + ": ");

names[i] = scanner.nextLine();

System.out.print("Enter marks for student " + (i + 1) + ": ");

marks[i] = scanner.nextDouble();

scanner.nextLine(); // Consume the newline character

// Calculate grade based on marks

if (marks[i] >= 90) {

grades[i] = 'A';

} else if (marks[i] >= 80) {

grades[i] = 'B';

} else if (marks[i] >= 70) {


grades[i] = 'C';

} else if (marks[i] >= 60) {

grades[i] = 'D';

} else {

grades[i] = 'F';

scanner.close();

System.out.println("Mark List:");

// Print student information and grades

for (int i = 0; i < numStudents; i++) {

System.out.println("Name: " + names[i]);

System.out.println("Marks: " + marks[i]);

System.out.println("Grade: " + grades[i]);

System.out.println();

OUTPUT

Enter the number of students:2

Enter the name of the student Bob

Enter the mark of the student:80


Enter the name of the student :Ron

Enter the mark of the student:65

Mark list

Name : Bob

Mark : 80

Grade : B

Name : Ron

Mark : 65

Grade :D

You might also like