Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
WEEK 3 CLASS’S EXAMPLES
Monday Class (Section 1):
import java.util.Scanner;
public class MondaySection1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input1 = new Scanner (System.in);
int anyNumber;
System.out.println(" enter a number: ");
anyNumber = input1.nextInt();
if (( anyNumber> 0) || (anyNumber==0) ){
System.out.println(" the number is positive");
}
else {
System.out.println(" the number is negative");
}
/*
Scanner input1 = new Scanner (System.in);
int anyNumber;
System.out.println(" enter a number: ");
anyNumber = input1.nextInt();
if ( ( (anyNumber %2) ==0) && ((anyNumber %3) ==0)
) {
System.out.println(" the number is a
multplication of 6 ");
}
else {
System.out.println(" the number is not a
multplication of 6");
}
*/
/*
int
x =
y =
z =
if
x, y, z;
10;
20;
40;
( (x<y) && (x<z) ) {
System.out.println (x + " is the smallest ");
}
else{
System.out.println (x + " is not the smallest
");
}
*/
/*
int x, y;
x = 30;
y = 20;
if (x<y) {
System.out.println (x + " is less than "+ y);
}
*/
}
}
Monday Class (Section 2):
import java.util.Scanner;
public class Section2MondayExample {
public static void main(String[] args) {
Scanner inputDevice = new Scanner( System.in );
System.out.print( "Please enter the x-Value : " );
int x;
x = inputDevice.nextInt();
System.out.print( "Please enter the y-Value : " );
int y;
y = inputDevice.nextInt();
int width = 10;
int height = 5;
if ( (-5<=x) && (x<=5) && (-2.5<=y) && (y<=2.5 ) ) {
System.out.print( "Within the rectangle " );
}
else{
System.out.print( "Outside the rectangle " );
}
/*
int month = 2;
int year = 2017;
int numDays = 0;
switch (month) {
case 1: case 3: case 5:
case 7: case 8: case 10:
case 12:
numDays = 31;
break;
case 4: case 6:
case 9: case 11:
numDays = 30;
break;
case 2:
if (((year % 4 == 0) && !(year % 100 == 0))
|| (year % 400 == 0))
numDays = 29;
else
numDays = 28;
break;
default:
System.out.println("Invalid month.");
break;
}
System.out.println("Number of Days = " + numDays);
*/
/*
Scanner inputDevice = new Scanner( System.in );
System.out.print( "Please enter the month (1-12) : "
);
int month = inputDevice.nextInt();
String monthString;
switch (month) {
case 1: monthString = "January";
break;
case 2: monthString = "February";
break;
case 3: monthString = "March";
break;
case 4: monthString = "April";
break;
case 5: monthString = "May";
break;
case 6: monthString = "June";
break;
case 7: monthString = "July";
break;
case 8: monthString = "August";
break;
case 9: monthString = "September";
case 10:
case 11:
case 12:
default:
break;
monthString
break;
monthString
break;
monthString
break;
monthString
break;
= "October";
= "November";
= "December";
= "Invalid month";
}
System.out.println(monthString);
*/
/*
Scanner data1 = new Scanner (System.in);
System.out.println("enter student grade: ") ;
int anyGrade;
anyGrade = data1.nextInt();
if ( (anyGrade>=90) ) {
System.out.println(" Student get A ")
}
else if ( (anyGrade>=80) && (anyGrade<=89)
System.out.println(" Student get B ")
}
else if ( (anyGrade>=70) && (anyGrade<=79)
System.out.println(" Student get C ")
}
else if ( (anyGrade>=60) && (anyGrade<=69)
System.out.println(" Student get D ")
}
else {
System.out.println(" Student get F ")
}
*/
;
) {
;
) {
;
) {
;
;
/*
Scanner data1 = new Scanner (System.in);
System.out.println("enter a number ") ;
int anyNumber;
anyNumber = data1.nextInt();
boolean result= anyNumber % 2 ==0;
if (result==true){
System.out.println(anyNumber + " is even ") ;
}
else{
System.out.println(anyNumber + " is odd ") ;
}
*/
}
}
Wednesday Class (Section 1):
import java.util.Scanner;
public class Section1WednesdaySelection {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
int age;
Scanner inputDevice = new Scanner( System.in );
System.out.print( "Please enter Age: " );
age = inputDevice.nextInt();
switch ( age )
{
case 18:
System.out.println( "age 18" );
break;
case 19:
System.out.println( "age 19" );
break;
default:
System.out.println( "not matched" );
break;
}
*/
/*
Scanner data1 = new Scanner (System.in);
int Temp;
System.out.println(" enter a Temp : ");
Temp = data1.nextInt();
if ( Temp <= 32){
System.out.println("Freezing");
}
else if ( (32< Temp) && (Temp<= 49) ) {
System.out.println("Cold");
}
else if ( (49< Temp) && (Temp<= 65) ) {
System.out.println("Chill");
}
else if ( (65< Temp) && (Temp<= 80) ) {
System.out.println("Hot");
}
*/
/*
Scanner data1 = new Scanner (System.in);
int Temp;
System.out.println(" enter a Temp : ");
Temp = data1.nextInt();
switch (Temp) {
case 32 : System.out.println("Freezing");
break;
case 33 :
case 34 :
case 35 :
case 36 :
case 37 :
case 38 :
case 39 :
case 40 :
case 41 :
case 42 :
case 43 :
case 44 :
case 45 :
case 46 :
case 47 :
case 48 :
case 49 : System.out.println("Cold");
break ;
}
*/
}
}
Wednesday Class (Section 2):
import java.util.Scanner;
public class W3WedSection2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
Scanner InputData = new Scanner (System.in);
int weight;
System.out.println("Enter the weight of the
package: ");
weight = InputData.nextInt();
double cost=0.0;
if
( weight >0 && weight<=1){
cost = 3.5;
}
else if ( weight<=3){
cost = 5.5;
}
else if ( weight<=10){
cost = 8.5;
}
else if ( weight<=20){
cost = 10.5;
}
else if (weight >20){
System.out.println("We cant ship this
package");
}
System.out.println("The cost is " + cost);
*/
/*
Scanner InputData = new Scanner (System.in);
int weight;
System.out.println("Enter the weight of the
package: ");
weight = InputData.nextInt();
double cost=0.0;
switch (weight){
case 1 : cost =3.5; break ;
case 2 :
case 3 : cost =5.5; break;
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10 :cost = 8.5; break;
default :
cost =0;
}
System.out.println("The cost is " + cost);
*/
/*
Scanner InputData = new Scanner (System.in);
int side1, side2, side3;
System.out.println("Enter side 1: ");
side1 = InputData.nextInt();
System.out.println("Enter side 2: ");
side2 = InputData.nextInt();
System.out.println("Enter side 3: ");
side3 = InputData.nextInt();
int Perimter=0;
/*
if ( ( (side1 + side2) > side3 ) && (
side3) > side1 ) && ( (side1 + side3) > side2
Perimter = side1 + side2 + side3;
}
else{
Perimter = 0;
}
*/
/*
if ( !( (side1 + side2) > side3 ) ||
side3) > side1 ) || !( (side1 + side3) > side2
Perimter = 0;
}
else{
Perimter = side1 + side2 + side3;
}
(side2 +
) ) {
!( (side2 +
) ) {
System.out.println("The perimter is " +Perimter );
*/
double x = 2.0 / 3;
double y = 0.5632541258;
System.out.printf ("x is %4.2f
}
}
%6.3f", x , y);
Friday Class (Section 1):
import java.util.Scanner;
public class W3FSection1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
Scanner data = new Scanner (System.in);
System.out.println(" enter the weight of the
package: ");
double weight;
weight = data.nextDouble();
double cost=0.0;
if ( (weight >0 )
cost = 3.5;
}
else if ( (weight
cost = 5.5;
}
else if ( (weight
cost = 8.5;
}
else if ( (weight
cost = 10.5;
}
else if (weight >
cost =-1;
}
&& (weight <=1) ){
>1 ) && (weight <=3) ){
>3 ) && (weight <=10) ){
>10 ) && (weight <=20) ){
50){
if (cost==-1) {
System.out.println (" we cant ship this
package") ;
}
else {
System.out.println (" package will cost " +
cost) ;
}
*/
/*
Scanner data = new Scanner
System.out.println(" enter
int number1 ;
number1 = data.nextInt();
System.out.println(" enter
int number2 ;
number2 = data.nextInt();
System.out.println(" enter
int number3 ;
number3 = data.nextInt();
(System.in);
number 1: ");
number 2: ");
number 3: ");
if ( (number1 > number2 ) && (number1>number3) ){
System.out.println(number1 + " is the
largest");
}
else if ( (number2 > number1 ) && (number2>number3)
){
System.out.println(number2 + " is the
largest");
}
else{
System.out.println(number3 + " is the
largest");
}
*/
/*
double R= 1113.5214587;
boolean E = false ;
System.out.printf ("%5.3e-%-6b " , R , E );
*/
/*
for (int R =10 ; R <= 20; R++){
System.out.println("Good morning");
}
*/
/*
for (int R =10 ; R <= 20; R++){
System.out.println(R);
}
*/
/*
int R;
for (R =10 ; R <= 20; R++){
if (R %2==0) {
System.out.println(R);
}
}
*/
/*
for (int R =100 ; R > 0; R-=3){
System.out.println(R);
}
*/
for (int R =100 ; R > 101; R++){
System.out.println(R);
}
}
}
Friday Class (Section 2):
import java.util.Scanner;
public class W3FSection2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*
double x = 2.0 / 3;
System.out.println("x is " + (int) (x * 1000) /
1000.0);
double x1 = 2.0 / 3;
System.out.printf("x is %-10.3f", x1);
*/
/*
for (int W =11 ; W <=20 ; W++) {
System.out.println (" Hello");
}
*/
/*
for (int W =1 ; W <=10 ; W++) {
System.out.println (W);
}
*/
/*
for (int counter =-10 ; counter <=10 ; counter++) {
if (counter >=0) {
System.out.println (counter);
}
}
*/
/*
for (int counter =100 ; counter >0 ; counter--) {
System.out.println (counter);
}
for (int counter =5 ; counter <=50 ; counter++) {
if (counter%2==0) {
System.out.println (counter);
}
}
*/
/*
for (int counter =6 ; counter <=50 ; counter=
counter +2) {
System.out.println (counter);
}
*/
/*
int DC =0;
Scanner data = new Scanner (System.in);
for (int i =0 ; i <10 ; i++){
System.out.println ("Enter a number ") ;
int number = data.nextInt();
if (number%2 == 0) {
DC++;
}
}
System.out.println (" there are " + DC + " even
numbers");
*/
double total =0;
int counter =0;
Scanner data = new Scanner (System.in);
for (int i =0 ; i <10 ; i++){
System.out.println ("Enter a number ") ;
int number = data.nextInt();
if (number>0) {
counter ++;
total+= number;
}
}
System.out.println ("The total of all poisitive
numbers is " + total);
System.out.println ("The average of all poisitive
numbers is " + total/counter);
}
}