You are on page 1of 4

Java Task 1

 In this task you need to use any IDE to run the below code:

1) You need to create a new application to enter scores for students whereas (Jo= 50, Ehab=90, smith=80) and the result will
display as the below:

Name score grade message


---- ----- ----- -------
Jo 50 F oh!!!!
Ehab 90 A Excellent Job
Smith 80 B Great Job

package set1;

import java.util.Scanner;

public class task2 {


public static void main(String arg[]){
int Jo,Ehab,Smith;
String Grade = "",Message = "";
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Jo's Mark");
Jo = scanner.nextInt();

System.out.println("Enter Ehab's Mark");


Ehab = scanner.nextInt();

System.out.println("Enter Smith's Mark");


Smith = scanner.nextInt();
scanner.close();

System.out.println("Name Score Grade Message");


System.out.println("____ _____ _____ _______");

if(Jo>=90){
Grade="A";
Message="Excellent Job";
} else if (Jo>=75) {
Grade="B";
Message="Great Job";
} else if (Jo>50) {
Grade="C";
Message="Hard luck";
} else if (Jo<=50) {
Grade="F";
Message="Oh!!!!";
}
System.out.println("Jo "+Jo+" "+Grade+" "+Message);

1
if(Ehab>=90){
Grade="A";
Message="Excellent Job";
} else if (Ehab>=75) {
Grade="B";
Message="Great Job";
} else if (Ehab>50) {
Grade="C";
Message="Hard luck";
} else if (Ehab<=50) {
Grade="F";
Message="Oh!!!!";
}
System.out.println("Ehab "+Ehab+" "+Grade+" "+Message);

if(Smith>=90){
Grade="A";
Message="Excellent Job";
} else if (Smith>=75) {
Grade="B";
Message="Great Job";
} else if (Smith>50) {
Grade="C";
Message="Hard luck";
} else if (Smith<=50) {
Grade="F";
Message="Oh!!!!";
}
System.out.println("Smith "+Smith+" "+Grade+" "+Message);
}
}

2) Create a new application using while loop to print odd number for the range from 1-100

package set2;

import java.util.Scanner;

public class task1 {


public static void main(String args[]) {
int minimum = 1;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the number you need to find the odd number
between 1 and 100:");
int number = scanner.nextInt();
scanner.close();
while (number >= minimum && number <= 100) {
System.out.println(minimum);
minimum = minimum + 2;
}
}
}

2
3) Create a new application using do while loop to print odd number for the range from 1-100

package set2;

import java.util.Scanner;

public class task2 {


public static void main (String args []){
Scanner scanner= new Scanner (System.in);
boolean again =false;
int minimum = 1;
do{
System.out.println("Enter an number between 1 and 100");
int number = scanner.nextInt();
for (int i=1; i<=number ; i++){
if (i % 2 != 0)
System.out.println(i); }

System.out.println("Do you want to start again?");


again= scanner.nextBoolean();

} while (again);
scanner.close();
}
}

4) Create a new application using for loop to print even number for the range from 1-100

package set2;

import java.util.Scanner;

public class task3 {


public static void main (String args []){

//initialize the known values


int minimum =1;
Scanner scanner = new Scanner (System.in);
System.out.println("please enter an number between 1 and 100");
int number = scanner.nextInt();
for (int i=1 ; i<=number; i++){
if (i%2 == 0 )
System.out.println(i);
}
}
}

3
5) Create a new application using Nested loop to enter any number and print the stars based on the entered number example
( enter number 5 and the below is printed)

*
**
***
****
*****

package set2;

public class task4 {


public static void main (String args []){

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


for (int j=0 ; j<=i; j++){
System.out.print("*");
}
System.out.println();
}
}
}

You might also like