Sheet Java
1. Write a program to compute the area and circumference of a rectangle 3 inche wide by 5 inches long.
What changes must be made to the program so it works for a rectangle 6.8 inches wide by 2.3 inches long? public class AreaOfRectangle {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here int width=3,height=5;
// double width=6.8,height=2.3; int area,circumference;
// double area,circumference; area = width * height; circumference = 2 *( width + height);
System.out.println("The area of rectangle is "+ area+" the circumference is "+ circumference);
}
}
2- Write a program to print your name, and date of birth? …show more content…
public class YourName { public static void main(String[] args) {
System.out.println("My name is kamal and the date of my birth is 4/9/1984");
}
}
3- Write a program to sum up all the numbers in array?
package sum.of.the.array; import java.util.Scanner;
/**
*
* @author hayam
*/
public class SumOfTheArray {
/**
* @param args the command line arguments
1
*/ public static void main(String[] args) {
// TODO code application logic here int size,sum=0;
Scanner scan = new Scanner (System.in);
System.out.println("Enter the size of the array "); size=scan.nextInt(); int [] x = new int [size]; for( int i=0;i=81 || x==90)
System.out.println("B");
else if (x>=71 || x==80) …show more content…
System.out.println("C"); else if (x>=61 || x==70)
System.out.println("D");
else if (x>=0 || x==60)
System.out.println("F");
}
}
13- Modify the previous program to print out a + or - after the letter grade based on the last digit of the score.
The modifiers are listed in the following table
For example, 81=B-, 94=A, and 68=D+.
Note: n F is only an F. There is no F+ or F-. package grades; import java.util.Scanner;
11
/**
*
* @author hayam
*/
public class Grades {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Enter the numeric grades ");
Scanner scan = new Scanner (System.in); int x = scan.nextInt();
String aString = Integer.toString(x); if (x>100)
System.out.println("error,wrong input"); else if (x >=91 || x==100 )
{
if (aString.charAt(1)==56 || aString.charAt(1)==48|| aString.charAt(1)==57)// NUMBER 8
IN THE ASCI CODE IS 56 AND NUMBER 0 IN THE ASCI CODE 48 AND NUMBER 9 IN THE ASCI CODE IS 57
System.out.println("A+");
else if (aString.charAt(1)==49 || aString.charAt(1)==51|| aString.charAt(1)==50)
System.out.println("A-");
12
else
System.out.println("A");
} else if (x>=81 || x==90)
{
if (aString.charAt(1)==56 || aString.charAt(1)==48 || aString.charAt(1)==57)
System.out.println("B+");
if (aString.charAt(1)==49 || aString.charAt(1)==51 || aString.charAt(1)==50)
System.out.println("B-");
else
System.out.print("B ");
}
else if (x>=71 || x==80)
{
if (aString.charAt(1)==56 || aString.charAt(1)==48 || aString.charAt(1)==57)
System.out.println("C+");
else if (aString.charAt(1)==49 || aString.charAt(1)==51 || aString.charAt(1)==50)
System.out.println("C-");
else
System.out.println("C");
} else if (x>=61 || x==70)
{
if (aString.charAt(1)==56 || aString.charAt(1)==48 || aString.charAt(1)==57)
13
System.out.println("D+"); else if (aString.charAt(1)==49 || aString.charAt(1)==51|| aString.charAt(1)==50)
System.out.println("D-");
else
System.out.println("D");
} else if (x>=0 || x==60)
System.out.println("F");
}
}
14- Write a program that takes a series of numbers and counts the number of positive and negative values.
package count.positive; import java.util.Scanner;
/**
*
* @author hayam
*/
public class CountPositive {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
14
int size, count=0,n=0;
Scanner scan = new Scanner (System.in);
System.out.println("Enter the size of the array "); size= scan.nextInt(); int [] x = new int [size]; for( int i=0;i 0)
System.out.println("The positive value is " + ++ count); else if
(x[i]